-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbootstrap.sh
executable file
·128 lines (104 loc) · 2.3 KB
/
bootstrap.sh
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
set -euo pipefail
quiet=false
while getopts "q" opt; do
case $opt in
q) quiet=true ;;
*) exit 1 ;;
esac
done
config_home=${XDG_CONFIG_HOME:-"$HOME/.config"}
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
step_marker=•
ESeq="\x1b["
RCol="$ESeq"'0m'
Red="$ESeq"'0;31m'
Gre="$ESeq"'0;32m'
Yel="$ESeq"'0;33m'
echo_header() {
[ "$quiet" = true ] && return
printf "%$(tput cols)s" | tr ' ' '─'
echo -e "$1"
printf "%$(tput cols)s" | tr ' ' '─'
echo
}
echo_success() {
[ "$quiet" = true ] && return
echo -e "${Gre}$step_marker $1${RCol}"
}
echo_skip() {
[ "$quiet" = true ] && return
echo -e "${Yel}$step_marker $1${RCol}"
}
echo_error() {
[ "$quiet" = true ] && return
echo -e "${Red}$step_marker $1${RCol}"
}
echo_error_exit() {
[ "$quiet" = true ] || echo -e "${Red}$step_marker $1${RCol}\n"
exit 1
}
link_file() {
local source_file="$1"
local target_file="$2"
if ! [ -e "$source_file" ]; then
echo_error_exit "Source: $source_file does not exist"
fi
# If the target file is a symlink or doesn't exist, force a new symlink
if [ -L "$target_file" ] || ! [ -e "$target_file" ]; then
if [ "$(readlink "$target_file")" = "$source_file" ]; then
echo_skip "$target_file already linked"
else
ln -snf "$source_file" "$target_file"
echo_success "$source_file -> $target_file"
fi
else
echo_error "$target_file already exists as a non-symlink"
fi
}
echo_header "Creating config directory"
if ! [ -d "$config_home" ]; then
mkdir -p "$config_home"
echo_success "created $config_home"
else
echo_skip "$config_home already exists"
fi
echo_header "Symlink files to $config_home"
# Common
config_dots=(
bat
dircolors
git
lazygit
nvim
ripgrep
tmux
yazi
zsh
)
# macOS specific
if [[ "$OSTYPE" == "darwin"* ]]; then
config_dots+=(
aerospace
kitty
ghostty
hammerspoon
sketchybar
wezterm
)
fi
for file in "${config_dots[@]}"; do
source_file="$repo_root/$file"
target_file="$config_home/$file"
link_file "$source_file" "$target_file"
done
echo_header "Symlink files to $HOME"
home_dots=(
.zshenv
)
for file in "${home_dots[@]}"; do
source_file="$repo_root/$file"
target_file="$HOME/$file"
link_file "$source_file" "$target_file"
done
[ "$quiet" = true ] || echo -e "\nDone.\n"