-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathadd-plugin
More file actions
executable file
·93 lines (66 loc) · 1.25 KB
/
add-plugin
File metadata and controls
executable file
·93 lines (66 loc) · 1.25 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
#!/bin/bash
## Functions
usage()
{
cat <<EOF 1>&2
Usage: $(basename "$0") [OPTIONS] <url>
OPTIONS
-o Plugin is optional (use :packadd to load)
EOF
exit 1
}
repo_path()
{
local url=$1
local owner
owner="$(basename "$(dirname "$url")")"
echo "$owner/$(repo_name "$url")"
}
repo_name()
{
local url=$1
basename "$url" .git
}
toggling_optional_status()
{
test -d "$PACKAGE/$ALTERNATE_PARENT/$(repo_name "$URL")"
}
vim_script()
{
local path
path="$(repo_path "$URL")"
local options=""
if [ "$PARENT" = "opt" ]; then
options=", {'type': 'opt'}"
fi
printf " call minpac#add('%s'%s)" "$path" "$options"
}
## Main program
[ -n "$DEBUG" ] && set -x
set -euo pipefail
PACKAGE=pack/minpac
PARENT=start
ALTERNATE_PARENT=opt
while getopts ":o" OPT; do
case "$OPT" in
o)
PARENT=opt
ALTERNATE_PARENT=start
shift
;;
*)
usage
;;
esac
done
[ -z "${1+x}" ] && usage
URL="$1"
shift
git submodule add "$URL" $PACKAGE/$PARENT/"$(repo_name "$URL")"
if toggling_optional_status; then
git rm "$PACKAGE/$ALTERNATE_PARENT/$(repo_name "$URL")"
fi
cat <<EOF
Add this to packages.vim:
$(vim_script)
EOF