-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.sh
executable file
·201 lines (175 loc) · 4.22 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
#!/usr/bin/env bash
set -eo pipefail
app_name="FlyVim"
repo_uri="https://github.com/starifly/FlyVim.git"
repo_name="FlyVim"
repo_path="$HOME/.FlyVim"
repo_branch="master"
_all=
_vim=
_neovim=
_update=
help() {
cat << EOF
usage: $0 [OPTIONS]
--help Show this message
--all Install FlyVim for Vim and NeoVim
--vim Install FlyVim for Vim
--neovim Install FlyVim for NeoVim
--update Update FlyVim
EOF
}
for opt in "$@"; do
case $opt in
--help)
help
exit 0
;;
--all) _all=1 ;;
--vim) _vim=1 ;;
--neovim) _neovim=1 ;;
--update) _update=1 ;;
*)
echo "unknown option: $opt"
help
exit 1
;;
esac
done
###############################
## Basic tools
###############################
msg() {
printf '%b\n' "$1" >&2
}
success() {
if [ "$ret" -eq '0' ]; then
msg "\\33[32m[✔]\\33[0m ${1}${2}"
fi
}
error() {
msg "\\33[31m[✘]\\33[0m ${1}${2}"
exit 1
}
exists() {
command -v "$1" >/dev/null 2>&1
}
sync_repo() {
if [ ! -e "$repo_path" ]; then
msg "\\033[1;34m==>\\033[0m Trying to clone $repo_name"
mkdir -p "$repo_path"
git clone -b "$repo_branch" "$repo_uri" "$repo_path" --depth=1
ret="$?"
success "Successfully cloned $repo_name."
else
msg "\\033[1;34m==>\\033[0m Trying to update $repo_name"
cd "$repo_path" && git pull origin "$repo_branch"
ret="$?"
success "Successfully updated $repo_name"
fi
if [ -n "$_update" ]; then
exit 0;
fi
}
install_plugins() {
for exe in "$@"; do
eval "$exe +PlugInstall +qall"
done
ret="$?"
success "Successfully installed plugins via vim-plug"
}
backup() {
if [ -e "$1" ]; then
echo
msg "\\033[1;34m==>\\033[0m Attempting to back up your original vim configuration"
today=$(date +%Y%m%d_%s)
mv -v "$1" "$1.$today"
ret="$?"
success "Your original vim configuration has been backed up"
fi
}
install_for_vim() {
backup "$HOME/.vimrc"
msg "\\033[1;34m==>\\033[0m Trying to download vim-plug"
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
ret="$?"
success "Successfully downloaded vim-plug"
ln -sf "$HOME/.FlyVim/init.vim" "$HOME/.vimrc"
install_plugins "vim"
}
install_for_neovim() {
backup "$HOME/.config/nvim/init.vim"
msg "\\033[1;34m==>\\033[0m Trying to download vim-plug"
curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
ret="$?"
success "Successfully downloaded vim-plug"
mkdir -p "$HOME/.config/nvim"
ln -sf "$HOME/.FlyVim/init.vim" "$HOME/.config/nvim/init.vim"
install_plugins "nvim"
}
check_git() {
if ! exists "git"; then
error "You must have 'git' installed to continue"
fi
}
infer() {
if exists "vim" && exists "nvim"; then
echo "\\033[1;34m==>\\033[0m Find both 'vim' and 'nvim' in your system"
echo
while true; do
read -r -p " Install FlyVim for: [0]vim [1]nvim [2]vim and nvim :" opt
case $opt in
0)
install_for_vim
break
;;
1)
install_for_neovim
break
;;
2)
install_for_vim
install_for_neovim
break
;;
*)
echo "Please answer 0, 1 or 2"
;;
esac
done
elif exists "vim"; then
msg "\\033[1;34m==>\\033[0m Only find 'vim' in your system"
msg " Starting to install FlyVim for 'vim'"
install_for_vim
elif exists "nvim"; then
msg "\\033[1;34m==>\\033[0m Only find 'nvim' in your system"
msg " Starting to install FlyVim for 'nvim'"
echo
install_for_neovim
else
error "You must have 'vim' or 'nvim' installed to continue"
fi
}
install() {
if [ -n "$_all" ]; then
install_for_vim
install_for_neovim
return
fi
if [ -n "$_vim" ]; then
install_for_vim
fi
if [ -n "$_neovim" ]; then
install_for_neovim
fi
infer
}
###############################
## main
###############################
check_git
sync_repo
install
msg "\\nThanks for installing \\033[1;31m$app_name\\033[0m. Enjoy!"