-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpm.sh
executable file
·214 lines (174 loc) · 6.16 KB
/
vpm.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
#!/bin/sh
function usage() {
echo "Vim Package Manager
usage: vpm action [action-args]
For specific help about an action, do
$ vpm action help
Actions:
list : List all installed packages
install : Install a package
remove : Remove a package
update : Update a package (if no args follow, update all packages)
install-from-file : Install all packages listed in a file"
}
function list_packages_help() {
echo "Vim Package Manager
list : Lists all packages currently installed.
Change which directory to search for plugins in by setting $$PLUGIN_DIR in the .vpmrc.
By default it lists the plugins in ~/.vim/bundle"
}
function install_packages_help() {
echo "Vim Package Manager
Installs the packages that are listed as arguments following \"install\".
These strings will be concatenated with $$DOWNLOAD_URL_BASE, which can be set in the .vpmrc.
The default is https://github.com.
They will be downloaded to $$PLUGIN_DIR (default ~/.vim/bundle)
The download location will be saved in $$PLUGIN_DATA_FILE
Example usage:
$ vpm install tpope/vim-obsession tpope/vim-fugitive
clones https://github.com/tpope/vim-obsession into $$PLUGIN_DIR"
}
function remove_packages_help() {
echo "Vim Package Manager
Removes the packages that are listed as arguments following \"remove\".
Unlike with install, you don't need to supply anything except the directory name (e.g no GitHub username is needed).
The directory $$PLUGIN_DIR/<arg> will be deleted.
Also, if an entry for the removed package is in $$PLUGIN_DATA_FILE, it will be removed
Example usage:
$ vpm remove vim-obsession vim-fugitive"
}
function update_packages_help() {
echo "Vim Package Manager
Updates all packages that are found in $$PLUGIN_DIR
In the future, this should take as argument specific plugins to update, and update all plugins if no args are supplied"
}
function install_from_file_help() {
echo "Vim Package Manager
Installs all of the plugins listed in the file passed as an argument.
The file should have entries formatted as <plugin-name> : <download-url>
The spaces before and after the colon are required.
vpm will keep track of your plugins and their download locations in $$PLUGIN_DATA_FILE (default ~/.vim/vpm.txt)
so that if you want to download your plugins to a new machine, you only need to copy that file to your new machine and run
this command.
Example usage:
$ vpm install-from-file ~/.vim/vpm.txt"
}
function bootstrap_help() {
echo "Vim Package Manager: bootstrap
When first running vpm, it doesn't know where the plugins you already have were downloaded from.
It assumes that they were downloaded from a git repo.
bootstrap searches $$PLUGIN_DIR for each installed plugin, and checks where it was installed from, storing it in the
$$PLUGIN_DATA_FILE. This file just stores the names of plugins and where they were downloaded from, so that your plugins can easily
be installed on another machine with the install-from-file command."
}
function list_packages() {
ls $PLUGIN_DIR
}
function install_packages() {
local packages_arr=($@)
local len=$(expr $# - 1)
for i in `seq 1 $len`; do
local package=${packages_arr[$i]}
local package_name=$(echo $package | sed 's/.*\/\(.*\)/\1/g')
echo "Installing package from ${DOWNLOAD_URL_BASE}/$package into ${PLUGIN_DIR}/$package_name"
git clone ${DOWNLOAD_URL_BASE}/$package ${PLUGIN_DIR}/$package_name
echo "$package_name : ${DOWNLOAD_URL_BASE}/$package" >> ${PLUGIN_DATA_FILE}
done
}
function remove_packages() {
local packages_arr=($@)
local len=$(expr $# - 1)
for i in `seq 1 $len`; do
local package_name=${packages_arr[$i]}
echo "Removing ${PLUGIN_DIR}/$package_name"
rm -r ${PLUGIN_DIR}/$package_name
# Remove this plugin from the data file
local tmpfile=$(mktemp)
grep -v "$package_name" ${PLUGIN_DATA_FILE} > $tmpfile
mv $tmpfile ${PLUGIN_DATA_FILE}
done
}
function update_packages() {
for dir in $(ls $PLUGIN_DIR); do
cd $PLUGIN_DIR/$dir && git pull origin master
done
}
function install_from_file() {
local urls=$(sed 's/^\(.*\) : \(.*\)$/\1==DOWNLOAD-FROM==\2/g' $PLUGIN_DATA_FILE)
urls=($urls)
local len=$(expr ${#urls[@]} - 1)
for i in `seq 0 $len`; do
local name=$(echo ${urls[$i]} | sed 's/\(.*\)==DOWNLOAD-FROM==.*/\1/g')
local url=$(echo ${urls[$i]} | sed 's/.*==DOWNLOAD-FROM==\(.*\)/\1/g')
git clone $url $PLUGIN_DIR/$name
done
}
function bootstrap() {
local tmpfile=$(mktemp)
for dir in $(ls $PLUGIN_DIR); do
local url=$(cd $PLUGIN_DIR/$dir && git remote get-url origin)
echo "$dir : $url" >> $tmpfile
done
mv $tmpfile $PLUGIN_DATA_FILE
}
function main() {
if [ $# -eq 0 ]; then
usage
exit 0
fi
PLUGIN_DIR="$HOME/.vim/bundle"
DOWNLOAD_URL_BASE="https://github.com"
PLUGIN_DATA_FILE="$HOME/.vim/vpm.txt"
if [ -f "~/.vpmrc" ]; then
source ~/.vpmrc
fi
if [ "$2" = help ]; then
case "$1" in
"list")
list_packages_help
;;
"install")
install_packages_help
;;
"update")
update_packages_help
;;
"remove")
remove_packages_help
;;
"install-from-file")
install_from_file_help
;;
"bootstrap")
bootstrap_help
;;
*)
usage
esac
else
case "$1" in
"list")
list_packages
;;
"install")
install_packages $@
;;
"update")
update_packages $@
;;
"remove")
remove_packages $@
;;
"install-from-file")
install_from_file $@
;;
"bootstrap")
bootstrap
;;
*)
usage
esac
fi
exit 0
}
main $@