-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
executable file
·145 lines (124 loc) · 5.32 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
main() {
# check if tput is installed if is installed then set coloration
if which tput >/dev/null 2>&1; then
ncolors=$(tput colors)
fi
if [ -t 1 ] && [ -n "$ncolors" ] && [ "$ncolors" -ge 8 ]; then
RED="$(tput setaf 1)"
GREEN="$(tput setaf 2)"
YELLOW="$(tput setaf 3)"
BLUE="$(tput setaf 4)"
BOLD="$(tput bold)"
NORMAL="$(tput sgr0)"
else
RED=""
GREEN=""
YELLOW=""
BLUE=""
BOLD=""
NORMAL=""
fi
set -e
umask g-w,o-w
printf "${GREEN}------------------------------------------------\n"
printf "${BLUE}${BOLD}Installing automated vim config.${NORMAL}\n"
printf "${GREEN}------------------------------------------------\n"
printf "${NORMAL}"
# check if git is installed
hash git >/dev/null 2>&1 || {
printf "${RED}Error: ${BOLD}GIT${NORMAL}${RED} is not installed.\nPlease run \`sudo apt install -y git\` to install it.${NORMAL}\n"
echo "Error: git is not installed\n"
exit 1
}
hash ccze >/dev/null 2>&1 || {
printf "${RED}Error: ${BOLD}CCZE${NORMAL}${RED} is not installed.\nPlease run \`sudo apt install -y git\` to install it.\n"
exit 1
}
# Cloning remote repository
CURRENT_DATE=$(date +%Y%m%d_%H%M%S)
VIMRC=~/.vimrc
VIM_FOLDER=~/.vim
VIM_DOT_FOLDER=$HOME/.vim.dotfile
YCM_FOLDER=$VIM_FOLDER/plugged/YouCompleteMe
# Check if dotfile already present
if [ -d "$VIM_DOT_FOLDER" ]; then
printf "${YELLOW}You already have the dotfile installed.${NORMAL}\n"
printf "${YELLOW}Removing old installation folder and backing up previous vim settings.${NORMAL}\n"
rm -fr $HOME/.vim.dotfile
exit
fi
# Check if any emacs config was already installed
if [ -d "$VIM_FOLDER" ]; then
printf "${YELLOW}${BOLD} • Backing up VIM folder.${NORMAL}\n"
printf "${GREEN}------------------------------------------------${NORMAL}\n"
tar -czf "$HOME/.vim_$CURRENT_DATE.tar.gz" $VIM_FOLDER
printf "${GREEN}------------------------------------------------${NORMAL}\n"
rm -fr $VIM_FOLDER
fi
if [ -f "$VIMRC" ]; then
printf "${YELLOW}${BOLD} • Backing up VIM config file.${NORMAL}\n"
printf "${GREEN}------------------------------------------------${NORMAL}\n"
tar -czf "$HOME/.vimrc_$CURRENT_DATE.tar.gz" $VIMRC
printf "${GREEN}------------------------------------------------${NORMAL}\n"
printf "${NORMAL}\n"
rm -fr $VIMRC
fi
if [ "$OSTYPE" = cygwin ]; then
if git --version | grep msysgit > /dev/null; then
echo "Error: Windows/MSYS Git is not supported on Cygwin"
echo "Error: Make sure the Cygwin git package is installed and is first on the path"
exit 1
fi
fi
env git clone --depth=1 https://github.com/Nickael/vim.dotfiles $VIM_DOT_FOLDER || {
printf "Error: git clone of dofile repo failed\n"
exit 1
}
printf "${GREEN}------------------------------------------------\n"
printf "${YELLOW}${BOLD} • Cloning new Vim Plug repos before installing plugins${NORMAL}\n"
printf "${GREEN}------------------------------------------------\n"
printf "${NORMAL}\n"
mkdir -v $HOME/.vim
printf "${NORMAL}\n"
# git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
# using Plug instead of Vundle as package manager
curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
}
main
cp -fr $VIM_DOT_FOLDER/vimrc $VIMRC
printf "${GREEN}------------------------------------------------\n"
printf "${YELLOW}${BOLD} • Removing temporary cloned dot files folder...${NORMAL}\n"
rm -fr $VIM_DOT_FOLDER
printf "${GREEN}------------------------------------------------\n"
printf "${YELLOW}${BOLD} • Installing Vim pluging now...${NORMAL}\n"
printf "${GREEN}------------------------------------------------${NORMAL}\n"
vim -es -u vimrc -i NONE -c "PlugInstall" -c "qa" | ccze -A && echo ' '
echo "${GREEN}------------------------------------------------"
printf "${YELLOW}${BOLD} • Plugin installed\n"
echo "${GREEN}------------------------------------------------${NORMAL}"
if [ -d "$YCM_FOLDER" ]; then
hash cmake >/dev/null 2>&1 || {
printf "${RED}Error: ${BOLD}CMAKE${NORMAL}${RED} is not installed.\nPlease run \`sudo apt install -y cmake\` to install it.${NORMAL}\n"
echo "Error: cmake is not installed\n"
exit 1
}
hash gcc >/dev/null 2>&1 || {
printf "${RED}Error: ${BOLD}gcc${NORMAL}${RED} is not installed.\nPlease run \`sudo apt install -y gcc\` to install it.${NORMAL}\n"
echo "Error: gcc is not installed\n"
exit 1
}
hash gpp >/dev/null 2>&1 || {
printf "${RED}Error: ${BOLD}gpp${NORMAL}${RED} is not installed.\nPlease run \`sudo apt install -y gpp\` to install it.${NORMAL}\n"
echo "Error: gpp is not installed\n"
exit 1
}
hash g++ >/dev/null 2>&1 || {
printf "${RED}Error: ${BOLD}g++${NORMAL}${RED} is not installed.\nPlease run \`sudo apt install -y g++\` to install it.${NORMAL}\n"
echo "Error: g++ is not installed\n"
exit 1
}
printf "${YELLOW}${BOLD} • Building YCM.${NORMAL}\n"
echo "${GREEN}------------------------------------------------${NORMAL}"
exec $YCM_FOLDER/install.py --all | ccze -A
exit
fi