forked from chxuan/vimplus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·420 lines (368 loc) · 10.9 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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
#!/bin/bash
# 获取平台类型,mac还是linux平台
function get_platform_type()
{
echo $(uname)
}
# 获取linux发行版名称
function get_linux_distro()
{
if grep -Eq "Ubuntu" /etc/*-release; then
echo "Ubuntu"
elif grep -Eq "Deepin" /etc/*-release; then
echo "Deepin"
elif grep -Eq "LinuxMint" /etc/*-release; then
echo "LinuxMint"
elif grep -Eq "elementary" /etc/*-release; then
echo "elementaryOS"
elif grep -Eq "Debian" /etc/*-release; then
echo "Debian"
elif grep -Eq "CentOS" /etc/*-release; then
echo "CentOS"
elif grep -Eq "openSUSE" /etc/*-release; then
echo "openSUSE"
elif grep -Eq "Arch Linux" /etc/*-release; then
echo "ArchLinux"
elif grep -Eq "ManjaroLinux" /etc/*-release; then
echo "ManjaroLinux"
else
echo "Unknow"
fi
}
# 判断是否是ubuntu14.04LTS版本
function is_ubuntu1404()
{
version=$(cat /etc/lsb-release | grep "DISTRIB_RELEASE")
if [ ${version} == "DISTRIB_RELEASE=14.04" ]; then
echo 1
else
echo 0
fi
}
# 在ubuntu上源代码安装vim
function compile_vim_on_ubuntu()
{
sudo apt-get remove -y vim vim-runtime gvim
sudo apt-get remove -y vim-tiny vim-common vim-gui-common vim-nox
sudo rm -rf /usr/bin/vim*
sudo rm -rf /usr/local/bin/vim*
sudo rm -rf /usr/share/vim/vim*
sudo rm -rf /usr/local/share/vim/vim*
rm -rf ~/vim81
sudo apt-get install -y libncurses5-dev libncurses5 libgnome2-dev libgnomeui-dev \
libgtk2.0-dev libatk1.0-dev libbonoboui2-dev \
libcairo2-dev libx11-dev libxpm-dev libxt-dev python-dev python3-dev ruby-dev lua5.1 lua5.1-dev
git clone https://gitee.com/chxuan/vim81.git ~/vim81
cd ~/vim81
./configure --with-features=huge \
--enable-multibyte \
--enable-rubyinterp \
--enable-pythoninterp \
--with-python-config-dir=/usr/lib/python2.7/config-x86_64-linux-gnu \
--enable-perlinterp \
--enable-luainterp \
--enable-gui=gtk2 \
--enable-cscope \
--prefix=/usr
make
sudo make install
cd -
}
# 在debian上源代码安装vim
function compile_vim_on_debian()
{
sudo apt-get remove -y vim vim-runtime gvim
sudo apt-get remove -y vim-tiny vim-common vim-gui-common vim-nox
sudo rm -rf /usr/bin/vim*
sudo rm -rf /usr/local/bin/vim*
sudo rm -rf /usr/share/vim/vim*
sudo rm -rf /usr/local/share/vim/vim*
rm -rf ~/vim81
sudo apt-get install -y libncurses5-dev libncurses5 libgtk2.0-dev libatk1.0-dev libcairo2-dev libx11-dev libxpm-dev libxt-dev python-dev python3-dev ruby-dev lua5.1 lua5.1-dev
git clone https://gitee.com/chxuan/vim81.git ~/vim81
cd ~/vim81
./configure --with-features=huge \
--enable-multibyte \
--enable-rubyinterp \
--enable-pythoninterp \
--with-python-config-dir=/usr/lib/python2.7/config-x86_64-linux-gnu \
--enable-perlinterp \
--enable-luainterp \
--enable-gui=gtk2 \
--enable-cscope \
--prefix=/usr
make
sudo make install
cd -
}
# 在centos上源代码安装vim
function compile_vim_on_centos()
{
sudo rm -rf /usr/bin/vi
sudo rm -rf /usr/bin/vim*
sudo rm -rf /usr/local/bin/vim*
sudo rm -rf /usr/share/vim/vim*
sudo rm -rf /usr/local/share/vim/vim*
rm -rf ~/vim81
sudo yum install -y ruby ruby-devel lua lua-devel luajit \
luajit-devel ctags git python python-devel \
python34 python34-devel tcl-devel \
perl perl-devel perl-ExtUtils-ParseXS \
perl-ExtUtils-XSpp perl-ExtUtils-CBuilder \
perl-ExtUtils-Embed libX11-devel ncurses-devel
git clone https://gitee.com/chxuan/vim81.git ~/vim81
cd ~/vim81
./configure --with-features=huge \
--enable-multibyte \
--with-tlib=tinfo \
--enable-rubyinterp=yes \
--enable-pythoninterp=yes \
--with-python-config-dir=/lib64/python2.7/config \
--enable-perlinterp=yes \
--enable-luainterp=yes \
--enable-gui=gtk2 \
--enable-cscope \
--prefix=/usr
make
sudo make install
cd -
}
# 安装mac平台必要软件
function install_prepare_software_on_mac()
{
brew install vim gcc cmake ctags-exuberant curl ack
}
# 安装ubuntu必要软件
function install_prepare_software_on_ubuntu()
{
sudo apt-get update
ubuntu1404=`is_ubuntu1404`
if [ ${ubuntu1404} == 1 ]; then
sudo apt-get install -y cmake3
else
sudo apt-get install -y cmake
fi
sudo apt-get install -y exuberant-ctags build-essential python python-dev python3-dev fontconfig curl libfile-next-perl ack-grep git
compile_vim_on_ubuntu
}
# 安装debian必要软件
function install_prepare_software_on_debian()
{
sudo apt-get update
sudo apt-get install -y cmake exuberant-ctags build-essential python python-dev python3-dev fontconfig curl libfile-next-perl ack git
compile_vim_on_debian
}
# 安装centos必要软件
function install_prepare_software_on_centos()
{
sudo yum install -y ctags automake gcc gcc-c++ kernel-devel cmake python-devel python3-devel curl fontconfig ack git
compile_vim_on_centos
}
# 安装archlinux必要软件
function install_prepare_software_on_archlinux()
{
sudo pacman -S --noconfirm vim ctags automake gcc cmake python3 python2 curl ack git fontconfig
sudo ln -s /usr/lib/libtinfo.so.6 /usr/lib/libtinfo.so.5
}
# 安装opensuse必要软件
function install_prepare_software_on_opensuse()
{
sudo zypper install -y vim ctags gcc gcc-c++ cmake python-devel python3-devel curl ack fontconfig git ncurses5-devel
}
# 拷贝文件
function copy_files()
{
rm -rf ~/.vimrc
ln -s ${PWD}/.vimrc ~
rm -rf ~/.vimrc.local
cp ${PWD}/.vimrc.local ~
rm -rf ~/.ycm_extra_conf.py
ln -s ${PWD}/.ycm_extra_conf.py ~
mkdir ~/.vim
rm -rf ~/.vim/colors
ln -s ${PWD}/colors ~/.vim
rm -rf ~/.vim/ftplugin
ln -s ${PWD}/ftplugin ~/.vim
}
# 安装mac平台字体
function install_fonts_on_mac()
{
rm -rf ~/Library/Fonts/Droid\ Sans\ Mono\ Nerd\ Font\ Complete.otf
cp ./fonts/Droid\ Sans\ Mono\ Nerd\ Font\ Complete.otf ~/Library/Fonts
}
# 安装linux平台字体
function install_fonts_on_linux()
{
mkdir ~/.fonts
rm -rf ~/.fonts/Droid\ Sans\ Mono\ Nerd\ Font\ Complete.otf
cp ./fonts/Droid\ Sans\ Mono\ Nerd\ Font\ Complete.otf ~/.fonts
fc-cache -vf ~/.fonts
}
# 下载插件管理软件vim-plug
function download_vim_plug()
{
curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
}
# 安装vim插件
function install_vim_plugin()
{
vim -c "PlugInstall" -c "q" -c "q"
}
# 在linux上安装ycm插件
function install_ycm_on_linux()
{
git clone https://gitee.com/chxuan/YouCompleteMe_linux_with_clang.git ~/.vim/plugged/YouCompleteMe
cd ~/.vim/plugged/YouCompleteMe
python2.7 ./install.py --clang-completer
}
# macos编译ycm, 原始方法
function compile_ycm_on_mac_legacy()
{
cd ~/.vim/plugged/YouCompleteMe
python2.7 ./install.py --clang-completer --system-libclang
}
# macos编译ycm, Mojave上的方法
function compile_ycm_on_mac_mojave()
{
echo "Installing macOS_10.14 sdk headers..."
xcode-select --install
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
cd ~/.vim/plugged/YouCompleteMe
python2.7 ./install.py --clang-completer --system-libclang
}
# 在MacOS上安装ycm插件
function install_ycm_on_mac()
{
git clone https://gitee.com/chxuan/YouCompleteMe.git ~/.vim/plugged/YouCompleteMe
product_version=$(sw_vers | grep ProductVersion)
version=${product_version#*:}
main_version=${version%.*}
if [ ${main_version} == "10.14" ]; then
compile_ycm_on_mac_mojave
else
compile_ycm_on_mac_legacy
fi
}
# 打印logo
function print_logo()
{
color="$(tput setaf 6)"
normal="$(tput sgr0)"
printf "${color}"
echo ' __ __ '
echo '__ __/_/___ ___ ____ / /_ _______ '
echo '\ \ / / / __ `__ \/ __ \/ / / / / ___/ '
echo ' \ V / / / / / / / /_/ / / /_/ (__ ) '
echo ' \_/_/_/ /_/ /_/ ,___/_/\____/____/ '
echo ' /_/ ...is now installed!'
echo ''
echo ''
echo 'Just enjoy it!'
echo 'p.s. Follow me at https://github.com/chxuan.'
echo ''
printf "${normal}"
}
# 在mac平台安装vimplus
function install_vimplus_on_mac()
{
install_prepare_software_on_mac
copy_files
install_fonts_on_mac
install_ycm_on_mac
download_vim_plug
install_vim_plugin
print_logo
}
# 开始安装vimplus
function begin_install_vimplus()
{
copy_files
install_fonts_on_linux
install_ycm_on_linux
download_vim_plug
install_vim_plugin
print_logo
}
# 在ubuntu上安装vimplus
function install_vimplus_on_ubuntu()
{
install_prepare_software_on_ubuntu
begin_install_vimplus
}
# 在debian上安装vimplus
function install_vimplus_on_debian()
{
install_prepare_software_on_debian
begin_install_vimplus
}
# 在centos上安装vimplus
function install_vimplus_on_centos()
{
install_prepare_software_on_centos
begin_install_vimplus
}
# 在archlinux上安装vimplus
function install_vimplus_on_archlinux()
{
install_prepare_software_on_archlinux
begin_install_vimplus
}
# 在opensuse上安装vimplus
function install_vimplus_on_opensuse()
{
install_prepare_software_on_opensuse
begin_install_vimplus
}
# 在linux平上台安装vimplus
function install_vimplus_on_linux()
{
distro=`get_linux_distro`
echo "Linux distro: "${distro}
if [ ${distro} == "Ubuntu" ]; then
install_vimplus_on_ubuntu
elif [ ${distro} == "Deepin" ]; then
install_vimplus_on_ubuntu
elif [ ${distro} == "LinuxMint" ]; then
install_vimplus_on_ubuntu
elif [ ${distro} == "elementaryOS" ]; then
install_vimplus_on_ubuntu
elif [ ${distro} == "Debian" ]; then
install_vimplus_on_debian
elif [ ${distro} == "CentOS" ]; then
install_vimplus_on_centos
elif [ ${distro} == "openSUSE" ]; then
install_vimplus_on_opensuse
elif [ ${distro} == "ArchLinux" ]; then
install_vimplus_on_archlinux
elif [ ${distro} == "ManjaroLinux" ]; then
install_vimplus_on_archlinux
else
echo "Not support linux distro: "${distro}
fi
}
# 获取当前时间戳
function get_now_timestamp()
{
cur_sec_and_ns=`date '+%s-%N'`
echo ${cur_sec_and_ns%-*}
}
# main函数
function main()
{
begin=`get_now_timestamp`
type=`get_platform_type`
echo "Platform type: "${type}
if [ ${type} == "Darwin" ]; then
install_vimplus_on_mac
elif [ ${type} == "Linux" ]; then
install_vimplus_on_linux
else
echo "Not support platform type: "${type}
fi
end=`get_now_timestamp`
second=`expr ${end} - ${begin}`
min=`expr ${second} / 60`
echo "It takes "${min}" minutes."
}
# 调用main函数
main