-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·445 lines (391 loc) · 11.3 KB
/
install.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
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
#!/usr/bin/env bash
### init
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
# assign DOTFILES to the directory where this script is located.
# it is supposed to be the root of the dotfiles repo, which you clone in your $HOME.
DOTFILES="${SCRIPT_DIR}"
# setup user config path for current operating system
platform="$(uname -s | tr '[:upper:]' '[:lower:]')"
case $platform in
linux)
USERCONFIG="$HOME/.config"
;;
darwin)
USERCONFIG="$HOME/Library/Application\ Support"
;;
*)
echo "Unknown platform, cannot default user config folder for current OS. Exiting..."
exit 2
;;
esac
### functions
function usage {
echo "./$0 [all|FEATURE_NAME|custom]"
}
function makedirs {
move_if_exists "${HOME}/bin"
ln -s ${DOTFILES}/bin ${HOME}/bin
mkdir -p ${HOME}/.config
mkdir -p ${HOME}/.local/bin
mkdir -p ${HOME}/.local/share/man/man1
mkdir -p ${HOME}/.local/share/man/man5
mkdir -p ${HOME}/bin2
mkdir -p ${HOME}/bin2/man
mkdir -p ${HOME}/bin2/man/man1
mkdir -p ${HOME}/bin2/man/man5
mkdir -p ${HOME}/code/contrib # contributions
mkdir -p ${HOME}/code/projects # my projects
mkdir -p ${HOME}/code/clones # read-only git clones
mkdir -p ${HOME}/code/Templates # read-only projects boilerplates
mkdir -p ${HOME}/code/Workspaces # code-station to try new stuff
}
function bashinstall {
move_if_exists "${HOME}/.bashrc"
ln -s ${DOTFILES}/bash/.bashrc ${HOME}/.bashrc
}
function bash_aliases_install {
move_if_exists "${HOME}/.bash_aliases"
ln -s ${DOTFILES}/bash/.bash_aliases ${HOME}/.bash_aliases
}
function ctagsinstall {
move_if_exists "${HOME}/.ctags"
ln -s "${HOME}/dotfiles/ctags/.ctags" "${HOME}/.ctags"
}
function fzfinstall {
move_if_exists "${HOME}/.fzf.zsh"
move_if_exists "${HOME}/.fzf.bash"
ln -s ${DOTFILES}/fzf/.fzf.zsh ${HOME}/.fzf.zsh
ln -s ${DOTFILES}/fzf/.fzf.bash ${HOME}/.fzf.bash
sed -i "s@/home/francesco@${HOME}@g" ${HOME}/.fzf.bash
sed -i "s@/home/francesco@${HOME}@g" ${HOME}/.fzf.zsh
}
function gitinstall {
move_if_exists "${HOME}/.gitconfig"
move_if_exists "${HOME}/.gitignore_global"
/bin/bash ${DOTFILES}/git/git_config.sh
ln -s ${DOTFILES}/git/.gitignore_global ${HOME}/.gitignore_global
}
function gpginstall {
mkdir -p ${HOME}/.gnupg
move_if_exists "${HOME}/.gnupg/gpg.conf"
move_if_exists "${HOME}/.gnupg/gpg-agent.conf"
ln -s "${DOTFILES}/gnupg/$(uname -s)/gpg.conf" ${HOME}/.gnupg/gpg.conf
ln -s "${DOTFILES}/gnupg/$(uname -s)/gpg-agent.conf" ${HOME}/.gnupg/gpg-agent.conf
}
function editorconfiginstall {
move_if_exists "${HOME}/.editorconfig"
ln -s ${DOTFILES}/editorconfig/.editorconfig ${HOME}/.editorconfig
}
function gamainstall {
move_if_exists "${USERCONFIG}/gama"
mkdir -p "${USERCONFIG}/gama"
ln -s ${DOTFILES}/gama/config.yaml ${USERCONFIG}/gama/config.yaml
}
function inputrcinstall {
move_if_exists "${HOME}/.inputrc"
ln -s ${DOTFILES}/inputrc/.inputrc ${HOME}/.inputrc
}
function htoprcinstall {
mkdir -p "${USERCONFIG}/htop"
move_if_exists "${USERCONFIG}/htop/htoprc"
ln -s ${DOTFILES}/htop/htoprc ${USERCONFIG}/htop/htoprc
}
function lazygitinstall {
mkdir -p "${USERCONFIG}/lazygit"
ln -s ${DOTFILES}/lazygit/config.yml ${USERCONFIG}/lazygit/config.yml
}
function lfinstall {
mkdir -p "${USERCONFIG}/lf"
move_if_exists "${USERCONFIG}/lf/lfrc"
move_if_exists "${USERCONFIG}/lf/icons"
ln -s "${DOTFILES}/lf/lfrc" "${USERCONFIG}/lf/lfrc"
ln -s "${DOTFILES}/lf/icons" "${USERCONFIG}/lf/icons"
}
function mcinstall {
move_if_exists "${USERCONFIG}/mc"
move_if_exists "${HOME}/.local/share/mc/skins"
mkdir -p "${USERCONFIG}/mc"
mkdir -p "${HOME}/.local/share/mc"
ln -s "${DOTFILES}/mc/config" "${USERCONFIG}/mc"
ln -s "${DOTFILES}/mc/skins" "${HOME}/.local/share/mc/skins"
}
function neofetchinstall {
move_if_exists "${USERCONFIG}/neofetch"
mkdir -p "${USERCONFIG}/neofetch"
ln -s "${DOTFILES}/neofetch/config.conf" "${USERCONFIG}/neofetch/config.conf"
}
function tmuxinstall {
move_if_exists "${HOME}/.tmux"
mkdir -p "${HOME}/.tmux/plugins"
git clone https://github.com/tmux-plugins/tpm ${HOME}/.tmux/plugins/tpm
move_if_exists "${HOME}/.tmux.conf"
ln -s "${DOTFILES}/tmux/.tmux.conf" "${HOME}/.tmux.conf"
#tmux start-server
#tmux new-session -d
#${HOME}/.tmux/plugins/tpm/scripts/install_plugins.sh
#tmux kill-server
tmux new-session -d "sleep 1" \
&& sleep 0.1 \
&& ${HOME}/.tmux/plugins/tpm/scripts/install_plugins.sh
# && tmux show-environment -g TMUX_PLUGIN_MANAGER_PATH
# setenv -g TMUX_PLUGIN_MANAGER_PATH "$HOME/.tmux/plugins/"
}
function viminstall {
move_if_exists "${HOME}/.vimrc"
if [[ ! -z "$1" ]]; then
ln -s ${DOTFILES}/vim/$1.vimrc ${HOME}/.vimrc
else
ln -s ${DOTFILES}/vim/.vimrc ${HOME}/.vimrc
fi
move_if_exists "${HOME}/.vim"
mkdir -p ${HOME}/.vim
ln -s ${DOTFILES}/vim/.vim/colors ${HOME}/.vim/colors
mkdir -p ${HOME}/.vim/swap && chmod 700 ${HOME}/.vim/swap
mkdir -p ${HOME}/.vim/backups && chmod 700 ${HOME}/.vim/backups
mkdir -p ${HOME}/.vim/undo && chmod 700 ${HOME}/.vim/undo
}
function nviminstall {
move_if_exists "${HOME}/.config/nvim"
mkdir -p "${HOME}/.config/nvim"
ln -s "${DOTFILES}/vim/.vimrc" "${HOME}/.config/nvim/init.vim"
ln -s "${DOTFILES}/vim/lua" "${HOME}/.config/nvim/lua"
mkdir -p ${HOME}/.config/nvim/swap && chmod 700 ${HOME}/.config/nvim/swap
mkdir -p ${HOME}/.config/nvim/backups && chmod 700 ${HOME}/.config/nvim/backups
mkdir -p ${HOME}/.config/nvim/undo && chmod 700 ${HOME}/.config/nvim/undo
}
function vimpynviminstall {
python3 -m pip install --upgrade pynvim
}
function vimplugininstall {
vim -E -s -u "$HOME/.vimrc" +PlugInstall +qall
}
function xplrinstall {
move_if_exists "${USERCONFIG}/xplr"
mkdir -p "${USERCONFIG}/xplr/plugins"
ln -s ${DOTFILES}/xplr/init.lua ${USERCONFIG}/xplr/init.lua
ln -s ${DOTFILES}/xplr/plugins.lua ${USERCONFIG}/xplr/plugins.lua
if command -v lua >/dev/null ; then
lua ${DOTFILES}/xplr/clone_plugins.lua
else
echo "WARNING: lua is not installed. Cannot clone xplr plugins. Install lua and run xplr/clone_plugins.lua manually."
fi
}
function yazi_install {
(
cd "${DOTFILES}/yazi" || exit 1
./install.sh
)
}
function zellij_install {
(
cd "${DOTFILES}/zellij" || exit 1
./install.sh
)
}
function zpreztoinstall {
# check for zsh
if [[ -z $ZSH_NAME ]]; then
echo "'zpreztoinstall' function is meant to be run by zsh shell. Quitting..."
exit 1
fi
zsh "${DOTFILES}/zsh/zprezto/zprezto_install.sh"
}
function shellfishinstall {
move_if_exists "${HOME}/.shellfishrc"
echo "downloading latest version of Secure ShellFish shell integration"
wget https://gist.github.com/palmin/46c2d0f069d0ba6b009f9295d90e171a/raw/.shellfishrc -O ${HOME}/.shellfishrc
}
function move_if_exists {
local target=$1
local suffix=".bkp.$(date +'%Y%m%d_%H%M%S')"
local backup_path="${target}${suffix}"
if [ -e "$target" ]; then
echo "$target exists. Moving to $backup_path"
mv "$target" "$backup_path"
fi
}
function do_codespace_symlinks {
move_if_exists "${DOTFILES}"
ln -s '/workspaces/.codespaces/.persistedshare/dotfiles' "${DOTFILES}"
}
function do_codespace_ohmyzsh_install {
move_if_exists "$HOME/.zprofile"
ln -s "${DOTFILES}/.codespaces/zsh/oh-my-zsh/.zprofile" "$HOME/.zprofile"
move_if_exists "$HOME/.zshenv"
ln -s "${DOTFILES}/.codespaces/zsh/oh-my-zsh/.zshenv" "$HOME/.zshenv"
move_if_exists "$HOME/.zshrc"
ln -s "${DOTFILES}/.codespaces/zsh/oh-my-zsh/.zshrc" "$HOME/.zshrc"
}
function do_codespace_setup_scripts {
(
cd "${DOTFILES}/setups" || exit 1
./bat.sh
./delta.sh
./fzf.sh
./lazygit.sh
./yq2.sh
./version_managers.sh
./zoxide.sh
)
}
function run_all_setup_scripts {
local scripts_dir="${DOTFILES}/setups"
# execute all scripts in the scripts dir
for script in "$scripts_dir"/*.sh; do
if [ -f "$script" ] && [ -x "$script" ]; then
"$script"
fi
done
}
function quit_if_no_codespace {
if ! uname -a | grep -qi codespaces ; then
echo "** STOP! This is not a codespace! **"
echo "This script is meant to be run in a GitHub Codespace without params."
echo "It is a safety measure to avoid messing up the local dotfiles environment."
exit 101
fi
}
### actual script
echo "
Note: This script can be run in bash (no args) or in zsh (with args).
Bash run is designed to be performed by GitHub Codespaces.
Check the code to know more.
"
# if no args are given, default to bash shell and
# fewer customizations to provide compatibility with GitHub Codespaces.
if [ $# -eq 0 ]; then
quit_if_no_codespace
# it may be unset in Codespaces
USERCONFIG="$HOME/.config"
DOTFILES="$HOME/dotfiles"
# prepare codespace env by symlink dotfiles folder.
# this isn't cloned in the Codespace $HOME by the Codespace creation process
do_codespace_symlinks
# create directories before calling install functions
makedirs
# install just aliases, because .bashrc is populated with Codespaces specific stuff
bash_aliases_install
do_codespace_ohmyzsh_install
editorconfiginstall
fzfinstall
gitinstall
lazygitinstall
shellfishinstall
do_codespace_setup_scripts
exit 0;
fi
if [ $# -ne 1 ]; then
usage
exit 1
fi
cd "$HOME" || exit 1
case "$1" in
binaries)
run_all_setup_scripts
;;
all)
makedirs
bashinstall
fzfinstall
gitinstall
gpginstall
editorconfiginstall
inputrcinstall
htoprcinstall
lazygitinstall
tmuxinstall
viminstall
vimpynviminstall
vimplugininstall
nviminstall
zpreztoinstall
shellfishinstall
ctagsinstall
lfinstall
mcinstall
yazi_install
xplrinstall
zellij_install
neofetchinstall
gamainstall
;;
ctags)
ctagsinstall
;;
editorconfig)
editorconfiginstall
;;
fzf)
fzfinstall
;;
gama)
gamainstall
;;
git)
gitinstall
;;
gpg)
gpginstall
;;
htoprc)
htoprcinstall
;;
inputrc)
inputrcinstall
;;
lazygit)
lazygitinstall
;;
lf)
lfinstall
;;
makedirs)
makedirs
;;
mc)
mcinstall
;;
neofetch)
neofetchinstall
;;
nvim)
nviminstall
;;
tmux)
tmuxinstall
;;
vim)
viminstall
vimpynviminstall
vimplugininstall
;;
vim-noplugins)
viminstall
;;
vim-minimal)
viminstall minimal
vimplugininstall
;;
xplr)
xplrinstall
;;
yazi)
yazi_install
;;
zellij)
zellij_install
;;
zsh)
zpreztoinstall
;;
shellfish)
shellfishinstall
;;
custom)
echo "Open the script and place functions to exec below this line"
exit 0
;;
*)
usage
exit 1
esac