-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvim-setup.sh
More file actions
executable file
·144 lines (138 loc) · 4.02 KB
/
vim-setup.sh
File metadata and controls
executable file
·144 lines (138 loc) · 4.02 KB
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
#!/bin/bash
download_plugins() {
plugin_list_file=$1
while read -r line
do
cd ${HOME}/.vim/bundle
IFS=";" tokens=($line)
if [ ! -d "${tokens[0]}" ]; then
eval "git clone ${tokens[1]}"
else
echo "${tokens[0]} already downloaded"
fi
cd ${HOME}/vim-setup
done < $plugin_list_file
}
update_plugins() {
plugin_list_file=$1
while read -r line
do
cd ${HOME}/.vim/bundle
IFS=";" tokens=($line)
if [ ! -d "${tokens[0]}" ]; then
echo "${tokens[0]} can't be updated: It does not exist"
else
cd ${tokens[0]}
eval "git pull origin master"
cd ${HOME}/.vim/bundle
fi
cd ${HOME}/vim-setup
done < $plugin_list_file
}
add_plugin() {
plugin_list_file=$1
plugin_folder_name=$2
plugin_git_address=$3
already_added=false
while read -r line
do
cd ${HOME}/.vim/bundle
IFS=";" tokens=($line)
if [ "${tokens[0]}" == "$plugin_folder_name" ]; then
already_added=true
fi
cd ${HOME}/vim-setup
done < $plugin_list_file
if [ $already_added == true ]; then
echo "$plugin_folder_name was already in the plugin list"
else
echo "$plugin_folder_name;$plugin_git_address" >> $plugin_list_file
cd ${HOME}/.vim/bundle
eval "git clone $plugin_git_address"
cd ${HOME}/vim-setup
echo "Added $plugin_folder_name to the plugin list"
fi
}
remove_plugin() {
plugin_list_file=$1
plugin_folder_name=$2
already_added=false
temp_plugin_list_file="tmp.vim"
while read -r line
do
IFS=";" tokens=($line)
if [ "${tokens[0]}" == "$plugin_folder_name" ]; then
already_added=true
fi
done < $plugin_list_file
if [ $already_added == true ]; then
while read -r line
do
IFS=";" tokens=($line)
if [ "${tokens[0]}" != "$plugin_folder_name" ]; then
echo "${tokens[0]};${tokens[1]}" >> $temp_plugin_list_file
fi
done < $plugin_list_file
eval "mv $temp_plugin_list_file $plugin_list_file"
eval "rm -rf ${HOME}/.vim/bundle/$plugin_folder_name"
echo "Deleted $plugin_folder_name folder and removed it from the plugin list"
else
echo "$plugin_folder_name not found"
fi
}
display_help() {
printf "usage: vim-setup [--help]\n"
printf "\t\t <command> [<args>]\n\n"
printf "These commands are available:\n\n"
printf "Initialize environment\n"
printf "\tinit\t\tInstall pathogen and intialize the ~/.vim/bundle folder and plugins.vim file\n"
printf "\tinstall\t\tDownloads all plugins listed in plugins.vim and replaces ~/.vimrc\n\n"
printf "Manage plugins\n"
printf "\tupdate\t\tPulls latest commits from all master branches of plugins\n"
printf "\tadd <p1> <p2>\tAdds a plugin (p1 = git folder name) to the plugin list and clones its repo (p2 = git repo URL)\n"
printf "\tremove <p1>\tRemoves a plugin (p1 = git folder name) from the plugin list and deletes its repo\n"
}
if [[ $1 == "init" ]]; then
# install vim-pathogen
string=`dpkg -l | grep vim-pathogen`
if [[ $string == *"pathogen"* ]]; then
echo "vim-pathogen already installed"
else
sudo apt-get install vim-pathogen
fi
# create .vim directory
if [ ! -d "${HOME}/.vim" ]; then
mkdir ${HOME}/.vim
else
echo "${HOME}/.vim directory already exists"
fi
# create bundle directory
if [ ! -d "${HOME}/.vim/bundle" ]; then
mkdir ${HOME}/.vim/bundle
else
echo "${HOME}/.vim/bundle directory already exists"
fi
# create plugins.vim if not yet existing
if [ ! -f "plugins.vim" ]; then
touch plugins.vim
echo "No plugins.vim found: Empty plugins.vim created"
else
echo "Existing plugins.vim found"
fi
elif [[ $1 == "install" ]]; then
# download plugins
download_plugins plugins.vim
# rename existing .vimrc
mv ${HOME}/.vimrc ${HOME}/.vimrc_old
# copy .vimrc to home directory
cp .vimrc ${HOME}/.
echo "Copied .vimrc to home directory"
elif [[ $1 == "update" ]]; then
update_plugins plugins.vim
elif [[ $1 == "add" ]]; then
add_plugin plugins.vim $2 $3
elif [[ $1 == "remove" ]]; then
remove_plugin plugins.vim $2
elif [[ $1 == "--help" ]]; then
display_help
fi