-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvim-pack-remove
executable file
·97 lines (88 loc) · 1.95 KB
/
vim-pack-remove
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
#! /usr/bin/env bash
repo_dir="$HOME/.vim/pack/git-plugins"
silent=false
supports_long_opts=false
getopt --test > /dev/null
if (( $? == 4 )); then
supports_long_opts=true
fi
####
# This handles the optional arguments
###
SHORT=hsd:
LONG=help,silent,git-dir:
if [[ $supports_long_opts == true ]]; then
PARSED=$(getopt --options $SHORT --longoptions $LONG --name "$0" -- "$@")
else
PARSED=$(getopt --options $SHORT --name "$0" -- "$@")
fi
if (( $? != 0 )); then
echo 'Failed to parse arguments'
exit 2
fi
eval set -- "$PARSED"
while true; do
case "$1" in
-h|--help)
usage=true
break
;;
-d|--git-dir)
repo_dir=$2
shift 2
;;
-s|--silent)
silent=true
shift
;;
--)
shift
break
;;
*)
shift
;;
esac
done
if [[ $usage == true ]]; then
echo 'usage: vim-pack remove [-s|--silent] [-d <dir>| --git-dir=<dir>] [<opt|start>] <name>'
echo
echo '<name> specifies the package name'
echo
echo 'options:'
echo ' -s| --silent'
echo ' to hide output that normally goes to stdout'
echo
echo ' -d <dir> | --git-dir=<dir>'
echo ' specify the name for the package directory by default it is'
echo ' $HOME/.vim/pack/git-plugins'
echo
echo 'note:'
echo ' long options are only available with systems that have an enhanced version'
echo ' of getopt.'
if [[ $supports_long_opts == true ]]; then
echo ' this system does support long options'
else
echo ' this system does not support long options'
fi
exit 0
fi
if (( $# == 2 )); then
start_opt=$1
pack_name=$2
if [[ "$silent" == true ]]; then
rm -rf "${repo_dir:?}/$start_opt/$pack_name" > /dev/null
else
rm -rf "${repo_dir:?}/$start_opt/$pack_name"
fi
elif (( $# == 1 )); then
pack_name=$1
if [[ "$silent" == true ]]; then
rm -rf "$repo_dir/start/$pack_name" > /dev/null
rm -rf "$repo_dir/opt/$pack_name" > /dev/null
else
rm -rf "$repo_dir/start/$pack_name"
rm -rf "$repo_dir/opt/$pack_name"
fi
fi
exit $?