-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
347 lines (323 loc) · 10.1 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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
#!/usr/bin/env bash
# Configures vim and plugins
# Author: Pierre Visconti
# Github: https://github.com/petrosvisconte
set -euo pipefail
### Checks files before running installation
function check_files {
local FILE=~/vim_configuration
if [ ! -d "${FILE}" ]; then
echo "${FILE} does not exist"
exit 1
fi
FILE=~/vim_configuration/colors
if [ ! -d "${FILE}" ]; then
echo "${FILE} does not exist"
exit 1
fi
FILE=~/vim_configuration/.vimrc
if [ ! -f "${FILE}" ]; then
echo "${FILE} does not exist"
exit 1
fi
}
### Copies files from github clone to user's directory
function copy_files {
local FILE=~/.vimrc
# Prompts user to overwrite or exit if they already have an existing .vimrc
if [ -f "${FILE}" ]; then
local dec=
until [ "${dec}" == y ] || [ "${dec}" == n ]; do
read -p $'\n'"A .vimrc has already been created. Overwrite file? [y/n]: " dec
done
if [ "${dec}" == n ]; then
echo "> Install canceled"
exit 1
fi
fi
# Creates necessary directories if they do not already exist
FILE=~/.vim
if [ ! -d "${FILE}" ]; then
mkdir -p ~/.vim/colors
else
FILE=~/.vim/colors
if [ ! -d "${FILE}" ]; then
mkdir ~/.vim/colors
fi
fi
# Copies the files
cp ~/vim_configuration/.vimrc ~
cp ~/vim_configuration/colors/* ~/.vim/colors
}
### Allows user to select their color mode and appends necessary code to .vimrc
function set_colormode {
local dec=
until [ "${dec}" == d ] || [ "${dec}" == l ]; do
echo -e "\nEnter your desired color mode (dark or light)."
read -p "This effects colorschemes and plugins with light and dark variants built in. [d/l]: " dec
done
if [ "${dec}" == d ]; then
echo 'set background=dark' >> ~/.vimrc
echo "> dark mode set"
else
echo 'set background=light' >> ~/.vimrc
echo "> light mode set"
fi
# Appends colorscheme comment for later
echo '" colorscheme' >> ~/.vimrc
}
### Allows user to select color scheme of their choice and appends necessary code to .vimrc
function set_colorscheme {
local color
echo -e "\nEnter the name of the desired colorscheme. Do not include the file extension."
read -p "(Or press <enter> to list all available colors): " color
if [ "${color}" == "" ]; then
echo -e "\n"
ls ~/.vim/colors
echo -e "\n"
read -p "Enter the name of the desired colorscheme: " color
fi
local FILE=~/.vim/colors/${color}.vim
# Checks if color.vim is available
if [ ! -f "${FILE}" ]; then
until [ -f "${FILE}" ]; do
read -p "Color cannot be found, enter a valid name: " color
FILE=~/.vim/colors/$color.vim
done
fi
echo "< ${FILE} set as colorscheme"
# Appends colorscheme chosen to vim config file
echo "colorscheme ${color}" >> ~/.vimrc
echo 'highlight Comment cterm=italic' >> ~/.vimrc
}
### Installs and setups vim-plug
function install_vimplug {
# Prompts user if they would like to install vim-plug and plugins
local dec=
until [ "${dec}" == y ] || [ "${dec}" == n ]; do
read -p $'\n'"Install vim-plug (required to install plugins) [y/n]: " dec
done
if [ "${dec}" == n ]; then
echo "> Setup complete"
exit 0
fi
# vim-plug
curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
echo '' >> ~/.vimrc
echo '" vim-plug plugins' >> ~/.vimrc
echo 'call plug#begin()' >> ~/.vimrc
echo 'call plug#end()' >> ~/.vimrc
echo '> vim-plug installed'
}
### Installs plugin using vim :PlugInstall command
function plug_install {
vim +'PlugInstall --sync' +qa
}
### Installs users statusbar of choice
# Calls the following functions:
# install_lightline
# install_airline
function install_statusbar {
local dec=
until [ "${dec}" == y ] || [ "${dec}" == n ]; do
read -p $'\n'"Install a status bar? [y/n]: " dec
done
if [ "${dec}" == y ]; then
echo -e "\nAvailable status bars:"
echo '1) lightline'
echo '2) airline'
read -p "Select your status bar: " dec
max_retry=0
while [ TRUE ] && [ "${max_retry}" -lt 5 ]; do
case "${dec}" in
1)
install_lightline
break
;;
2)
install_airline
break
;;
*)
read -p "Not a valid choice, try again: " dec
((++max_retry))
;;
esac
done
fi
}
### Installs and setups lightline
# Gets called by the following functions:
# install_statusbar
function install_lightline {
# adds lightline to plugins in .vimrc
sed -i "/call plug#begin()/a Plug 'itchyny/lightline.vim'" ~/.vimrc
# installs lightline
plug_install
echo "> lightline installed"
# prompts user to select colorscheme for lightline
local color
echo -e "\nEnter the name of the desired colorscheme for lightline. Do not include the file extension."
read -p "(Or press <enter> to list all available colors): " color
if [ "${color}" == "" ]; then
echo -e "\n"
ls ~/.vim/plugged/lightline.vim/autoload/lightline/colorscheme
echo -e "\n"
read -p "Enter the name of the desired lightline colorscheme: " color
fi
local FILE=~/.vim/plugged/lightline.vim/autoload/lightline/colorscheme/${color}.vim
# Checks if color.vim is available
if [ ! -f "${FILE}" ]; then
until [ -f "${FILE}" ]; do
read -p "Color cannot be found, enter a valid name: " color
FILE=~/.vim/plugged/lightline.vim/autoload/lightline/colorscheme/${color}.vim
done
fi
# Appends lightline congfiguration to .vimrc file
{
echo ''
echo '" lightline config'
echo 'set noshowmode'
echo 'let g:lightline = {'
echo " \ 'colorscheme': '${color}',"
echo ' \ }'
} >> ~/.vimrc
echo "> ${FILE} set as colorscheme"
}
### Installs and setups airline
# Gets called by the following functions:
# install_statusbar
function install_airline {
# adds airline and airline themes to plugins in .vimrc
sed -i "/call plug#begin()/a Plug 'vim-airline/vim-airline'" ~/.vimrc
sed -i "/call plug#begin()/a Plug 'vim-airline/vim-airline-themes'" ~/.vimrc
# installs airline and airline themes
plug_install
echo "> airline installed"
# prompts user to select colorscheme for airline
local color
echo -e "\nEnter the name of the desired colorscheme for airline. Do not include the file extension."
read -p "(Or press <enter> to list all available colors): " color
if [ "${color}" == "" ]; then
echo -e "\n"
ls ~/.vim/plugged/vim-airline-themes/autoload/airline/themes
echo -e "\n"
read -p "Enter the name of the desired airline colorscheme: " color
fi
local FILE=~/.vim/plugged/vim-airline-themes/autoload/airline/themes/${color}.vim
# Checks if color.vim is available
if [ ! -f "${FILE}" ]; then
until [ -f "${FILE}" ]; do
read -p "Color cannot be found, enter a valid name: " color
FILE=~/.vim/plugged/vim-airline-themes/autoload/airline/themes/${color}.vim
done
fi
# Appends airline congfiguration to .vimrc file
cat >> ~/.vimrc <<-EOT
" airline configuration
let g:airline_theme='deus'
let g:airline_detect_modified=1
let g:airline_filetype_overrides = {
\ 'coc-explorer': [ 'CoC Explorer', '' ],
\ 'defx': ['defx', '%{b:defx.paths[0]}'],
\ 'fugitive': ['fugitive', '%{airline#util#wrap(airline#extensions#branch#get_head(),80)}'],
\ 'floggraph': [ 'Flog', '%{get(b:, "flog_status_summary", "")}' ],
\ 'gundo': [ 'Gundo', '' ],
\ 'help': [ 'Help', '%f' ],
\ 'minibufexpl': [ 'MiniBufExplorer', '' ],
\ 'nerdtree': [ get(g:, 'NERDTreeStatusline', 'NERD'), '' ],
\ 'startify': [ 'startify', '' ],
\ 'vim-plug': [ 'Plugins', '' ],
\ 'vimfiler': [ 'vimfiler', '%{vimfiler#get_status_string()}' ],
\ 'vimshell': ['vimshell','%{vimshell#get_status_string()}'],
\ 'vaffle' : [ 'Vaffle', '%{b:vaffle.dir}' ],
\ }
EOT
echo "> ${FILE} set as colorscheme"
}
### Installs and setups wakatime
function install_wakatime {
local dec=
# prompts to install
until [ "${dec}" == y ] || [ "${dec}" == n ]; do
read -p $'\n'"Install wakatime (coding activity and stats)?
Note: You will need to enter your API key into vim when prompted [y/n]: " dec
done
if [ "${dec}" == y ]; then
# adds wakatime to plugins in .vimrc
sed -i "/call plug#begin()/a Plug 'wakatime/vim-wakatime'" ~/.vimrc
# installs wakatime
plug_install
plug_install # calls second time for API key
echo "> wakatime installed"
fi
}
### Installs and setups nerdtree
function install_nerdtree {
local dec=
# prompts to install
until [ "${dec}" == y ] || [ "${dec}" == n ]; do
read -p $'\n'"Install NerdTree (file browser) [y/n]: " dec
done
if [ "${dec}" == y ]; then
# adds nerdtree to plugins in .vimrc
sed -i "/call plug#begin()/a Plug 'preservim/nerdtree'" ~/.vimrc
# installs nerdtree
plug_install
echo "> nerdtree installed"
# adds nerdtree configuration to vimrc
cat >> ~/.vimrc <<-EOT
" Nerdtree configuration
" Exit Vim if NERDTree is the only window remaining in the only tab.
autocmd BufEnter * if tabpagenr('$') == 1 && winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
" Close the tab if NERDTree is the only window remaining in it.
autocmd BufEnter * if winnr('$') == 1 && exists('b:NERDTree') && b:NERDTree.isTabTree() | quit | endif
EOT
fi
}
### Installs and setups undotree
function install_undotree {
local dec=
# prompts to install
until [ "${dec}" == y ] || [ "${dec}" == n ]; do
read -p $'\n'"Install undotree (keeps an edit history) [y/n]: " dec
done
if [ "${dec}" == y ]; then
# adds undotree to plugins in .vimrc
sed -i "/call plug#begin()/a Plug 'mbbill/undotree'" ~/.vimrc
# installs undotree
plug_install
echo "> undotree installed"
fi
}
### Installs and setups ycm
function install_ycm {
local dec=
# prompts to install
until [ "${dec}" == y ] || [ "${dec}" == n ]; do
read -p $'\n'"Install YouCompleteMe (Autosuggestions, auto complete, warnings/erros) [y/n]: " dec
done
if [ "${dec}" == y ]; then
# adds undotree to plugins in .vimrc
sed -i "/call plug#begin()/a Plug 'Valloric/YouCompleteMe'" ~/.vimrc
# installs undotree
plug_install
echo "> YouCompleteMe installed"
fi
}
### Main function
function main {
check_files
copy_files
set_colormode
set_colorscheme
install_vimplug
install_statusbar
install_wakatime
install_nerdtree
install_undotree
install_ycm
echo "> Selected plugins installed. You can find them in $HOME/.vim/plugged"
}
main "$@"