-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
216 lines (168 loc) · 4.47 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
#!/usr/bin/env bash
# This setup file is based on spf13-vim's bootstrap.sh.
# Thanks for spf13-vim.
app_name='space-vim'
dot_spacevim="$HOME/.spacevim"
[ -z "$APP_PATH" ] && APP_PATH="$HOME/.space-vim"
[ -z "$REPO_URI" ] && REPO_URI='https://github.com/liuchengxu/space-vim.git'
[ -z "$REPO_BRANCH" ] && REPO_BRANCH='master'
debug_mode='0'
[ -z "$VIM_PLUG_PATH" ] && VIM_PLUG_PATH="$HOME/.vim/autoload"
[ -z "$VIM_PLUG_URL" ] && VIM_PLUG_URL='https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim'
########## Basic setup 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
}
debug() {
if [ "$debug_mode" -eq '1' ] && [ "$ret" -gt '1' ];
then
msg "An error occurred in function \"${FUNCNAME[$i+1]}\" on line ${BASH_LINENO[$i+1]}, we're sorry for that."
fi
}
exists() {
command -v "$1" >/dev/null 2>&1
}
program_exists() {
local ret='0'
exists "$1" || { local ret='1'; }
# fail on non-zero return value
if [ "$ret" -ne 0 ];
then
return 1
fi
return 0
}
program_must_exist() {
# throw error on non-zero return value
if ! program_exists "$1";
then
error "You must have '$1' installed to continue."
fi
}
lnif() {
if [ -e "$1" ];
then
ln -sf "$1" "$2"
fi
ret="$?"
debug
}
########## Setup function
backup() {
if [ -e "$1" ];
then
msg "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."
debug
fi
}
sync_repo() {
local repo_path="$1"
local repo_uri="$2"
local repo_branch="$3"
local repo_name="$4"
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
debug
}
create_symlinks() {
local source_path="$1"
local target_path="$2"
lnif "$source_path/init.vim" "$target_path/.vimrc"
ret="$?"
success "Setting up vim symlinks."
debug
}
sync_vim_plug() {
if [ ! -f "$VIM_PLUG_PATH/plug.vim" ];
then
curl -fLo "$1/plug.vim" --create-dirs "$2"
fi
debug
}
setup_vim_plug(){
local system_shell="$SHELL"
export SHELL='/bin/sh'
vim \
"+PlugInstall!" \
"+PlugClean" \
"+qall"
export SHELL="$system_shell"
success "Now updating/installing plugins using vim-plug"
debug
}
generate_dot_spacevim(){
if [ ! -f "$dot_spacevim" ];
then
touch "$dot_spacevim"
(
cat <<DOTSPACEVIM
" You can enable the existing layers in space-vim and
" exclude the partial plugins in a certain layer.
" The command Layer is vaild in the function Layers().
" Use exclude option if you don't want the full Layer,
" e.g., Layer 'better-defaults', { 'exclude': 'itchyny/vim-cursorword' }
function! Layers()
" Default layers, recommended!
Layer 'fzf'
Layer 'unite'
Layer 'better-defaults'
endfunction
" Put your private plugins here.
function! UserInit()
" Space has been set as the default leader key,
" if you want to change it, uncomment and set it here.
" let g:spacevim_leader = "<\Space>"
" let g:spacevim_localleader = ','
" Install private plugins
" Plug 'extr0py/oni'
endfunction
" Put your costom configurations here, e.g., change the colorscheme.
function! UserConfig()
" If you enable airline layer and have installed the powerline fonts, set it here.
" let g:airline_powerline_fonts=1
" color desert
endfunction
DOTSPACEVIM
) >"$dot_spacevim"
fi
}
########## Main()
program_must_exist "vim"
program_must_exist "git"
backup "$HOME/.vimrc"
sync_repo "$APP_PATH" \
"$REPO_URI" \
"$REPO_BRANCH" \
"$app_name"
create_symlinks "$APP_PATH" \
"$HOME"
sync_vim_plug "$VIM_PLUG_PATH" \
"$VIM_PLUG_URL"
generate_dot_spacevim
setup_vim_plug
msg "\nThanks for installing \033[1;31m$app_name\033[0m. Enjoy!"