diff options
Diffstat (limited to 'tools/compile_vim.sh')
-rwxr-xr-x | tools/compile_vim.sh | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/tools/compile_vim.sh b/tools/compile_vim.sh new file mode 100755 index 0000000..47115a9 --- /dev/null +++ b/tools/compile_vim.sh | |||
@@ -0,0 +1,94 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | set -e # exit when error | ||
4 | # environment variables here | ||
5 | |||
6 | VIMRUNTIME=/usr/share/vim/vim91 | ||
7 | color_file=industry.vim | ||
8 | |||
9 | # write a function to install sth,the parameter of the func is the packages | ||
10 | function install() { | ||
11 | sudo apt update | ||
12 | sudo apt upgrade | ||
13 | sudo apt remove vim* | ||
14 | sudo apt install -y git libatk1.0-dev libcairo2-dev liblua5.1-0-dev \ | ||
15 | libncurses5-dev libperl-dev libx11-dev libxpm-dev \ | ||
16 | libxt-dev lua5.1 python3-dev ruby-dev | ||
17 | } | ||
18 | |||
19 | # check current user is root or not, if is, warn the user | ||
20 | if [ $UID -eq 0 ]; then | ||
21 | echo -e "\033[31mYou are root, I recommand to use a normal user to run this script.\033[0m" | ||
22 | exit | ||
23 | fi | ||
24 | |||
25 | cd ~ | ||
26 | # if this is the first time to compile vim | ||
27 | if [ $# -eq 1 ] && [ $1 == "first" ]; then | ||
28 | install | ||
29 | if ! [ -d app ]; then | ||
30 | mkdir app | ||
31 | fi | ||
32 | cd app | ||
33 | echo -e "\033[32mGetting vim source code...\033[0m" | ||
34 | git clone https://github.com/vim/vim | ||
35 | cd vim/src | ||
36 | else | ||
37 | cd app/vim/src | ||
38 | sudo make uninstall | ||
39 | make distclean | ||
40 | echo -e "\033[32mGetting vim source code...\033[0m" | ||
41 | git pull | ||
42 | fi | ||
43 | |||
44 | # get the default python version | ||
45 | python_version=$(python3 -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $1"."$2}') | ||
46 | if [ -z $python_version ]; then | ||
47 | echo -e "\033[31mInstalling python3...\033[0m" | ||
48 | sudo apt update && sudo apt upgrade | ||
49 | sudo apt install python3 | ||
50 | python_version=$(python3 -V 2>&1 | awk '{print $2}' | awk -F '.' '{print $1"."$2}') | ||
51 | fi | ||
52 | # if gtk installed, remove it | ||
53 | if [ -d /usr/local/include/gtk-2.0 ]; then | ||
54 | sudo apt remove libgtk2.0-dev | ||
55 | fi | ||
56 | |||
57 | echo -e "\033[32mPython version: $python_version\033[0m" | ||
58 | |||
59 | echo -e "\033[32mConfiguring compile environment...\033[0m" | ||
60 | ./configure \ | ||
61 | --with-features=huge \ | ||
62 | --enable-multibyte \ | ||
63 | --enable-rubyinterp=dynamic \ | ||
64 | --with-ruby-command=/usr/bin/ruby \ | ||
65 | --enable-luainterp\ | ||
66 | --enable-python3interp=dynamic \ | ||
67 | --with-python3-command=$(which python$python_version) \ | ||
68 | --with-python3-config-dir=$(python$python_version-config --configdir) \ | ||
69 | --enable-perlinterp=dynamic \ | ||
70 | --enable-largefile \ | ||
71 | --enable-cscope \ | ||
72 | --with-compiledby="An Ordinary Communist weunite1848@gmail.com" \ | ||
73 | --enable-fail-if-missing \ | ||
74 | --disable-gui \ | ||
75 | --prefix=/usr | ||
76 | |||
77 | echo -e "\033[32mCompiling vim...\033[0m" | ||
78 | make | ||
79 | |||
80 | echo -e "\033[32mInstalling vim...\033[0m" | ||
81 | sudo make install | ||
82 | |||
83 | echo -e "\033[32;36mCompile done!\033[0m" | ||
84 | vim --version | head -n 3 | ||
85 | |||
86 | # test if the terminal support 256 colors, if so, configure the color file | ||
87 | if [ $(tput colors) -ge 256 ]; then | ||
88 | color_file=$VIMRUNTIME/colors/$color_file | ||
89 | echo -e "\033[32mConfiguring $color_file as transparent...\033[0m" | ||
90 | sudo sed -i '/if s:t_Co >= 256/,/hi Normal/{s/hi Normal/" hi/}' $color_file | ||
91 | sudo sed -i '/if s:t_Co >= 256/,/hi EndOfBuffer/{s/hi EndOfBuffer/" hi/}' $color_file | ||
92 | fi | ||
93 | |||
94 | echo -e "\033[32;36mDone.\033[0m" | ||