/
voom
executable file
·127 lines (107 loc) · 2.49 KB
/
voom
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
#!/usr/bin/env bash
#
# A Vim plugin manager designed to work with vim-pathogen.
#
# SYNOPSIS
#
# voom
# voom [update <name>]
# voom edit
#
# USAGE
#
# 1. Run `voom edit` to edit your plugin manifest.
# 2. Run `voom` to install/uninstall; `voom update` to update already-installed plugins.
#
set -e
VIM_DIR="${VIM_DIR:-$HOME/.vim}"
MANIFEST="$VIM_DIR/plugins"
BUNDLE_DIR="$VIM_DIR/bundle"
COMMENT='^#'
action="$1"
test -f "$MANIFEST" || {
echo >&2 "Could not locate '$MANIFEST'."
exit 1
}
edit_manifest() {
"${EDITOR:-vim}" "$MANIFEST"
}
is_remote_repo() {
local slashes="${1//[^\/]}"
local count="${#slashes}"
[ "$count" -eq 1 ]
}
install_plugin() {
local line="$1"
([ -z "$line" ] || [[ "$line" =~ $COMMENT ]]) && return
local plugin_name=${line##*/}
[ -d "$BUNDLE_DIR/$plugin_name" ] || {
if is_remote_repo "$line"; then
git clone --depth 1 "https://github.com/$line.git" "$BUNDLE_DIR/$plugin_name" >/dev/null 2>&1
else
ln -nfs "$line" "$BUNDLE_DIR/$plugin_name"
fi
echo "installed $plugin_name"
}
}
uninstall_plugin() {
local dir="$1"
[ -z "$dir" ] && return 1
plugin_name=${dir##*/}
(grep -v "$COMMENT" $MANIFEST | grep -q "$plugin_name" -) || {
rm -rf "$dir"
echo "uninstalled $plugin_name"
}
}
update_plugin() {
local dir="$1"
local plugin_name=${dir##*/}
[ -L "$dir" ] || {
cd "$dir"
upstream=$(git ls-remote --heads origin master | awk {'print $1'})
installed=$(git rev-parse master)
[ "$upstream" == "$installed" ] || {
git pull -q
# Ensure the string echoed to the console in 1 line only so we can run this function
# in the background without worrying about interleaved output.
echo "updated $plugin_name: $(git log --oneline "$installed".."$upstream" | wc -l) commit(s)"
}
}
}
install_missing_plugins() {
while read -r line; do
install_plugin "$line" &
done < "$MANIFEST"
wait
}
uninstall_unwanted_plugins() {
for dir in $BUNDLE_DIR/*; do
uninstall_plugin "$dir"
done
}
case $action in
'')
install_missing_plugins
uninstall_unwanted_plugins
;;
edit)
edit_manifest
install_missing_plugins
uninstall_unwanted_plugins
;;
update)
for dir in $BUNDLE_DIR/*; do
plugin_name=${dir##*/}
[ -n "$2" ] && [ "$2" != "$plugin_name" ] && continue
update_plugin "$dir" &
done
wait
;;
help | --help | -h)
echo "Usage: $(basename "$0") [update <name>] [edit]"
;;
*)
echo >&2 "Usage: $(basename "$0") [update <name>] [edit]"
exit 1
;;
esac