-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·221 lines (198 loc) · 4.74 KB
/
bootstrap.sh
File metadata and controls
executable file
·221 lines (198 loc) · 4.74 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/usr/bin/env zsh
_uname=$(uname -s)
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "${ncolors}" ] && [ "${ncolors}" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
BOLD="$(tput bold)"
RESET="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
RESET=""
fi
quit() {
echo "${BOLD}${YELLOW}>> Quitting${RESET}"
exit 1
}
command_exists() {
command -v "$@" >/dev/null 2>&1
}
yes_no="${RESET}(${GREEN}y${RESET}/${RED}n${RESET}/${YELLOW}q${RESET}) "
cd "$(dirname "${(%):-%N}")";
if [ "$1" != "--sync" -a "$1" != "-s" ]; then
git pull origin main --ff-only --quiet
fi
if [[ ! -v DOTFILES ]]; then
echo 'export DOTFILES="$HOME/.dotfiles"' >> ~/.zshenv.local
fi
function syncDotfiles() {
echo ""
echo "${BOLD}${BLUE}>> Syncing dotfiles${RESET}"
rsync \
--exclude ".git/" \
--exclude "scripts/" \
--exclude ".DS_Store" \
--exclude ".gitignore" \
--exclude "bootstrap.sh" \
--exclude "README.md" \
--exclude "LICENSE" \
--exclude "Rakefile" \
--include ".local/" \
--exclude "*.local" \
--exclude ".vscode/" \
--exclude "Library/" \
--exclude "macos_defaults" \
-avh --no-perms . ~;
if [[ "${_uname}" == "Darwin" ]]; then
for macOsDir in Library; do
rsync -avh --no-perms ${macOsDir} ~;
done
fi
echo "${GREEN}>> Done${RESET}"
source ~/.zshrc
source "${XDG_CONFIG_HOME}"/p10k.zsh
}
function switch_to_zsh() {
if [ "$(basename "${SHELL}")" = "zsh" ]; then
return
else
if ! command_exists -v chsh; then
cat <<-EOF
>> I can't change your shell automatically because this system does not have chsh.
${BLUE}>> Please manually change your default shell to zsh${RESET}
EOF
return
fi
if [[ "${_uname:0:5}" == "Linux" ]]; then
if ! grep "$(whoami)" /etc/passwd | grep -q zsh; then
echo "${BLUE}>> Changing default shell to zsh${RESET}"
chsh -s $(which zsh)
return
else
echo "${YELLOW}>> Default shell is already zsh${RESET}"
return
fi
fi
chsh -s $(which zsh)
return
fi
}
function install() {
if $2; then
echo "${BOLD}${BLUE}>> Installing ${1}${RESET}"
export _FORCE_INSTALL=true
if zsh ./scripts/"$1".zsh install; then
echo "${GREEN}>> Done${RESET}"
else
echo "${YELLOW}>> Already installed${RESET}"
fi
else
read "?Do you want to install ${1}? ${yes_no}"
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo "${BOLD}${BLUE}>> Installing ${1}${RESET}"
if zsh ./scripts/"$1".zsh install; then
echo "${GREEN}>> Done${RESET}"
else
echo "${YELLOW}>> Already installed${RESET}"
fi
elif [[ $REPLY =~ ^[Qq]$ ]]; then
quit
else
echo "${BLUE}>> Skipping ${1} installation${RESET}"
fi;
fi
}
function upgrade() {
echo "${BOLD}${BLUE}>> Upgrading ${1}${RESET}"
if zsh ./scripts/"$1".zsh upgrade; then
echo "${GREEN}>> Done${RESET}"
else
echo "${RED}>> An error occured when upgrading ${1}, please check manually${RESET}"
fi
}
scripts=(
atuin
bat
eza
ls_colors
nanorc
oh_my_zsh
powerlevel10k
step
yq
zsh_autosuggestions
zsh_completions
zsh_syntax_highlighting
zsh_you_should_use
)
if [[ "${_uname}" == "Darwin" ]]; then
scripts+=(
kubectl
kubectx
n
)
fi
if [ "$1" = "--force" -o "$1" = "-f" ]; then
for script in "${scripts[@]}";
do
install "${script}" true
done
switch_to_zsh;
syncDotfiles;
elif [ "$1" = "--upgrade" -o "$1" = "-u" ]; then
syncDotfiles;
# If second argument is given, upgrade only that script
if [ -n "$2" ]; then
upgrade "$2"
else
for script in "${scripts[@]}";
do
upgrade "${script}"
done
fi
syncDotfiles;
elif [ "$1" = "--sync" -o "$1" = "-s" ]; then
syncDotfiles;
elif [ "$1" = "--update" -o "$1" = "-u" ]; then
syncDotfiles;
else
for script in "${scripts[@]}";
do
install "${script}" false
done
if [ ! "$(basename "${SHELL}")" = "zsh" ]; then
read "?Do you want to switch to zsh? (${YELLOW}recommended${RESET}) ${yes_no}"
if [[ $REPLY =~ ^[Yy]$ ]]; then
switch_to_zsh;
elif [[ $REPLY =~ ^[Qq]$ ]]; then
quit
else
echo "${BLUE}>> Skipping switching to zsh${RESET}"
fi;
fi
read "?Do you want to sync the dotfiles? ${RED}This may overwrite existing files in your home directory.${RESET} ${yes_no}"
if [[ $REPLY =~ ^[Yy]$ ]]; then
syncDotfiles;
elif [[ $REPLY =~ ^[Qq]$ ]]; then
quit
else
echo "${BLUE}>> Skipping dotfile sync${RESET}"
fi;
fi
printf '%s' "${GREEN}"
printf '%s\n' ' __ __ _____ __ '
printf '%s\n' ' ____/ /___ / /_/ __(_) /__ _____ '
printf '%s\n' ' / __ / __ \/ __/ /_/ / / _ \/ ___/ '
printf '%s\n' ' _/ /_/ / /_/ / /_/ __/ / / __(__ ) '
printf '%s\n' '(_)__,_/\____/\__/_/ /_/_/\___/____/ '
printf '%s\n' ''
printf "${BLUE}%s\n" "Hooray! .dotfiles has been updated and/or is at the current version.${RESET}"
unset _uname