-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
235 lines (194 loc) · 5.23 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
#!/usr/bin/env bash
set -eu
app_name='xming-dotfiles'
APP_PATH="$(dirname "$PWD/$0")"
ZSH_CUSTOM="${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}"
options=(
"vim"
"oh-my-zsh"
"faster-zsh"
"programming"
"tmux-docker"
"sublime-vscode"
)
zsh_plugins=(
"z"
"git"
"zsh-users/zsh-autosuggestions"
"zdharma-continuum/fast-syntax-highlighting"
"zdharma-continuum/history-search-multi-word"
)
safe_source() { if [[ -s "$1" ]]; then source "$1"; fi }
for ff in "$APP_PATH"/common/*; do
# shellcheck disable=SC1090
source "$ff"
done
# shellcheck disable=SC1090
source "$APP_PATH/utils.sh"
safe_source ~/.work.zsh
############################ SETUP FUNCTIONS
print_select_menu() {
local prev="$PS3"
PS3=""
# dummy select
echo toto | select _ in "${options[@]}"; do break; done
PS3="$prev"
}
############################ MAIN FUNCTIONS
setup_vim() {
program_must_exist "git"
must_have_one_of "wget" "curl"
install_vim
install_neovim
create_vim_symlinks
setup_neovim
setup_vim_plug
}
install_oh_my_zsh() {
program_must_exist "zsh"
program_must_exist "git"
program_must_exist "curl"
local omz="https://raw.githubusercontent.com/\
robbyrussell/oh-my-zsh/master/tools/install.sh"
if [ ! -d "$HOME/.oh-my-zsh" ]; then
RUNZSH=no sh -c "$(curl -fsSL $omz)"
fi
success "oh my zsh installed."
}
install_omz_plugins() {
file_must_exist "$HOME/.zshrc"
file_must_exist "$HOME/.oh-my-zsh"
config_oh_my_zsh
common_config_zsh
# shellcheck disable=SC2046
zsh_plug $(reverse "${zsh_plugins[@]}")
}
custom_oh_my_zsh() {
install_oh_my_zsh
install_omz_plugins
}
custom_zinit() {
program_must_exist "git"
program_must_exist "zsh"
do_backup "$HOME/.zshrc" "pre-zinit"
config_zinit
common_config_zsh
}
config_programming_langs() {
program_must_exist "git"
must_have_one_of "wget" "curl"
for f in "$APP_PATH"/python/*; do
if [ -f "$f" ]; then
lnif "$f" "$HOME/.$(basename "$f")"
fi
done
install_miniforge
install_golang
install_go_tools
install_node
install_cargo
install_ruby
install_java
install_mingw
success "Now configuring programming."
}
config_tmux_docker() {
if program_exists tmux; then
safe_mkdir "$HOME/.tmux/plugins"
if [ ! -d ~/.tmux/plugins/tpm ]; then
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
fi
lnif "$APP_PATH/tmux/tmux.conf" "$HOME/.tmux.conf"
success "Now configuring tmux."
fi
if program_exists mpv; then
local mpv_conf="$HOME/.config/mpv"
safe_mkdir "$mpv_conf"
lnif "$APP_PATH/mpv/input.conf" "$mpv_conf"
success "Now configuring mpv."
fi
install_docker
}
config_sublime_vscode() {
is_macos && {
local bin="/usr/local/bin"
lnif /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl "$bin/subl"
lnif /Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code "$bin/code"
}
local sublime_home sublime_keymap
local link=lnif
is_linux && {
sublime_home="$HOME/.config/sublime-text-3/Packages/User"
sublime_keymap="Default (Linux).sublime-keymap"
}
is_macos && {
sublime_home="$HOME/Library/Application Support/Sublime Text/Packages/User"
sublime_keymap="Default (OSX).sublime-keymap"
}
is_wsl && {
link=cpif
sublime_home="$WINHOME/AppData/Roaming/Sublime Text/Packages/User"
sublime_keymap="Default (Windows).sublime-keymap"
}
local ff
if [[ -n "$sublime_home" ]] && [ -d "$sublime_home" ]; then
for ff in "$APP_PATH"/sublime/*.sublime-settings; do
$link "$ff" "$sublime_home"
done
$link "$APP_PATH/sublime/$sublime_keymap" "$sublime_home"
success "Now configuring sublime-text."
fi
if program_exists "code"; then
local code_home
is_linux && code_home="$HOME/.config/Code/User"
is_macos && code_home="$HOME/Library/Application Support/Code/User"
is_wsl && code_home="$WINHOME/AppData/Roaming/Code/User"
is_linux && increase_watch_limit
install_vscode_extensions
if [[ -n "$code_home" ]]; then
$link "$APP_PATH/vscode/settings.json" "$code_home"
$link "$APP_PATH/vscode/keybindings.json" "$code_home"
rm -rf "$code_home/snippets"
$link "$APP_PATH/vscode/snippets" "$code_home"
# if is_macos && xattr -l "/Applications/Visual Studio Code.app" | grep -q quarantine; then
# xattr -dr com.apple.quarantine "/Applications/Visual Studio Code.app"
# fi
success "Now configuring vscode."
fi
fi
}
bye() {
msg "Thanks for installing $app_name."
msg "© $(date +%Y) http://haomingw.github.io/"
exit
}
setup() {
case "$1" in
"vim") setup_vim ;;
"oh-my-zsh") custom_oh_my_zsh ;;
"faster-zsh") custom_zinit ;;
"programming") config_programming_langs ;;
"tmux-docker") config_tmux_docker ;;
"sublime-vscode") config_sublime_vscode ;;
*) error "Unexpected option: $1"; return 1 ;;
esac
}
select_setup() {
PS3='Please enter your choice: '
select option in "${options[@]}"; do
setup "$option"
confirm_finish
done
}
confirm_finish() {
# shellcheck disable=SC2015
confirm "Do you want to continue?" && print_select_menu || bye
}
main() {
if [ $# -eq 1 ]; then
setup "$1"
else
select_setup
fi
}
main "$@"