-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·164 lines (143 loc) · 3.49 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
#!/bin/bash
function check_prog() {
for prg in "$@"
do
if ! hash "$prg" > /dev/null 2>&1; then
echo "Command not found: $prg. Aborting..."
exit 1
fi
done
}
term_configs=(zsh nnn nvim tmux)
desktop_configs=(desktop alacritty)
function install_term() {
for e in "${term_configs[@]}"; do
stow --verbose=2 --target "$HOME" "$e"|| { echo -e "\n\nError: stow terminal failed" >&2; exit 1; }
done
echo -e "\n\nvim plugins:\n"
nvim --headless +PlugInstall +qall
# create dictionary for 'uga-rosa/cmp-dictionary' vim plugin
aspell -d en dump master | aspell -l en expand > ~/.config/nvim/en.dict
echo -e "\n\ntmux plugins:\n"
./tmux/.config/tmux/plugins/tpm/bin/install_plugins
echo -e "\n\nzsh plugins and theme:\n"
zsh -ic "fast-theme XDG:overlay"
}
function install_desktop() {
for e in "${desktop_configs[@]}"; do
stow --verbose=2 --target "$HOME" "$e" || { echo -e "\n\nError: stow desktop failed" >&2; exit 1; }
done
}
function update() {
local -a submodules_paths
local is_init=true
cd "$(dirname "$0")" || { echo "cd failure" >&2; exit 1; }
IFS=$'\n' read -r -d '' -a submodules_paths < <( git config --file .gitmodules --path --get-regexp 'submodule.*.path$' | cut -d " " -f 2 )
for i in "${submodules_paths[@]}"
do
if ! ls "$i"/.git >/dev/null 2>&1 ; then
echo >&2 "$i module not initialized."
is_init=false
fi
done
if [ "$is_init" = true ]; then
if [ -f "$HOME/.config/nvim/init.vim" ]; then
echo -e "\n\nvim plugins:\n"
nvim --headless +PlugUpdate +qall
fi
if [ -f "$HOME/.config/tmux/tmux.conf" ]; then
echo -e "\n\ntmux plugins:\n"
./tmux/.config/tmux/plugins/tpm/bin/update_plugins all
fi
if [ -f "$HOME/.zshrc" ]; then
echo -e "\n\nzsh plugins:\n"
zsh -i -c "zinit update --parallel | sed 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g'"
zsh -i -c "zinit self-update | sed 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g'"
fi
else
echo "Initializing repo submodules..."
git submodule update --checkout --init --jobs "$(nproc)" --depth 1
fi
}
function clear() {
for e in "${term_configs[@]}"; do
stow --verbose=2 -D --target "$HOME" "$e"
done
for e in "${desktop_configs[@]}"; do
stow --verbose=2 -D --target "$HOME" "$e"
done
}
function check_health() {
printf "Lines of colors should be continuous:\n"
curl -s https://raw.githubusercontent.com/JohnMorales/dotfiles/master/colors/24-bit-color.sh | bash
zsh -i -c "echo 123 | my-yank-to-clipboard "
}
usage="
$(basename "$0") [TYPE || OPTION]
script to install dotfiles
TYPE:
-t | --term
link dotfiles for programs that are available through terminal interface
install plugins with (nvim, tmux, zsh) plugin manager
-d | --desktop
link dotfiles for desktop programs
OPTION:
-u | --update
update:
nvim plugins
tmux plugins
zsh plugins
or initialize git submodules if they are not initialized already
-c | --clear
unlink configuration files from \$HOME
--checkhealth
check whether everything set up right
"
CLI=0
DESK=0
while (( $# )); do
case "$1" in
-t|--term)
CLI=1
shift
;;
-d|--desktop)
DESK=1
shift
;;
-h|--help)
echo "$usage"
exit
;;
-u|--update)
update
exit
;;
--checkhealth)
check_health
exit
;;
-c|--clear)
clear
exit
;;
-*)
echo "Error: Unsupported flag $1" >&2
exit 1
;;
esac
done
if [[ $CLI -eq 0 && $DESK -eq 0 ]]
then
echo "Error: specify --term or --desktop flags" >&2
exit 1
fi
check_prog stow curl zsh nvim tmux
if [[ $CLI -ne 0 ]]
then
install_term
fi
if [[ $DESK -ne 0 ]]
then
install_desktop
fi