forked from spf13/spf13-vim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·179 lines (146 loc) · 4.32 KB
/
bootstrap.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
#!/usr/bin/env bash
# Copyright 2014 Steve Francia
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
############################ SETUP PARAMETERS
app_name='spf13-vim'
[ -z "$APP_PATH" ] && APP_PATH="$HOME/.spf13-vim-cbg"
[ -z "$REPO_URI" ] && REPO_URI='https://github.com/Cabbage7th/spf13-vim.git'
[ -z "$REPO_BRANCH" ] && REPO_BRANCH='cbg'
debug_mode='0'
fork_maintainer='0'
[ -z "$VIMPLUG_URI" ] && VIMPLUG_URI="https://github.com/junegunn/vim-plug.git"
############################ 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
}
program_exists() {
local ret='0'
command -v $1 >/dev/null 2>&1 || { local ret='1'; }
# fail on non-zero return value
if [ "$ret" -ne 0 ]; then
return 1
fi
return 0
}
program_must_exist() {
program_exists $1
# throw error on non-zero return value
if [ "$?" -ne 0 ]; then
error "You must have '$1' installed to continue."
fi
}
variable_set() {
if [ -z "$1" ]; then
error "You must have your HOME environmental variable set to continue."
fi
}
lnif() {
if [ -e "$1" ]; then
ln -sf "$1" "$2"
fi
ret="$?"
debug
}
############################ SETUP FUNCTIONS
do_backup() {
if [ -e "$1" ] || [ -e "$2" ]; then
msg "Attempting to back up your original vim configuration."
today=`date +%Y%m%d_%s`
for i in "$1" "$2"; do
[ -e "$i" ] && [ ! -L "$i" ] && mv -v "$i" "$i.$today";
done
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"
msg "Trying to update $repo_name"
if [ ! -e "$repo_path" ]; then
mkdir -p "$repo_path"
git clone -b "$repo_branch" "$repo_uri" "$repo_path"
ret="$?"
success "Successfully cloned $repo_name."
else
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/.vimrc" "$target_path/.vimrc"
lnif "$source_path/.vimrc.plugs" "$target_path/.vimrc.plugs"
lnif "$source_path/.vimrc.local" "$target_path/.vimrc.local"
lnif "$source_path/coc-settings.json" "$target_path/.vim/coc-settings.json"
ret="$?"
success "Setting up vim symlinks."
debug
}
setup_vimplug() {
local system_shell="$SHELL"
export SHELL='/bin/sh'
vim \
-u "$1" \
"+set nomore" \
"+PlugInstall" \
"+PlugClean" \
"+qall"
export SHELL="$system_shell"
success "Now updating/installing plugins using vim-plug"
debug
}
############################ MAIN()
variable_set "$HOME"
program_must_exist "vim"
program_must_exist "git"
program_must_exist "yarn"
program_must_exist "clangd"
program_must_exist "npm"
program_must_exist "node"
do_backup "$HOME/.vim" \
"$HOME/.vimrc" \
sync_repo "$APP_PATH" \
"$REPO_URI" \
"$REPO_BRANCH" \
"$app_name"
sync_repo "$HOME/.vim/autoload" \
"$VIMPLUG_URI" \
"master" \
"vim-plug"
create_symlinks "$APP_PATH" \
"$HOME"
setup_vimplug "$HOME/.vimrc"
msg "\nThanks for installing $app_name."
msg "© `date +%Y` https://github.com/Cabbage7th/spf13-vim/"