-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup
executable file
·100 lines (78 loc) · 2.04 KB
/
setup
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/bin/bash
set -e
DOTFILES="$HOME/dotfiles"
echo_colored() { echo -e "${2}$1\033[0m"; }
echo_info() { echo_colored "==> $1" "\033[1;36m"; }
echo_info() {
gum style \
--foreground 212 --border-foreground 212 --border double \
--align left --width 50 --margin "1 0" --padding "0 1" \
"💁 $1"
}
fail() {
echo_colored "$1" "\033[1;31m"
exit 1
}
ensure_gum_installed() {
if ! type "gum" >/dev/null 2>&1; then
fail "gum is not installed. Run 'brew install gum' to install it and re-run this script."
fi
}
create_directories() {
echo_info "Creating directories"
for dir in "Code" "Writing" "bin" "tmp" ".ssh"; do
local _path="$HOME/$dir"
if [ -d "$_path" ]; then
echo "Directory already exists: $_path"
else
mkdir -p "$_path" && echo "Directory created successfully: $_path"
fi
done
}
symlink_files() {
local _files
local _symlinked
echo_info "Symlinking all files ending in '.symlink'"
_files=$(find "$DOTFILES" -name '*.symlink')
for abs_file in $_files; do
_symlinked=".$(basename "${abs_file%.symlink}")"
ln -sfv "$abs_file" "$HOME/$_symlinked"
done
}
copy_example_files() {
local _files
local _dst
echo_info "Copying all files ending in '.example'"
_files=$(find "$DOTFILES" -name '*.example')
for abs_file in $_files; do
_dst="$HOME/.$(basename "${abs_file%.example}")"
if [[ -s "$_dst" ]]; then
echo "File $_dst exists and will not be overridden"
else
cp -v "$abs_file" "$_dst"
fi
done
echo
}
run_install_scripts() {
echo_info "Running all install.sh scripts"
for file in $(find $DOTFILES -name 'install.sh'); do
gum style "🏗️ Running ${file#$DOTFILES/}" --foreground 33 --bold
echo
bash "$file"
echo
done
}
main() {
ensure_gum_installed
create_directories
symlink_files
copy_example_files
run_install_scripts
gum style "🚀 Setup complete!" \
--foreground 35 --bold \
--margin "1 0" --padding "0 1" \
--border "rounded" --border-foreground 35 \
--width 50 --align center
}
main "$@"