-
Notifications
You must be signed in to change notification settings - Fork 6
/
uninstall
executable file
·72 lines (65 loc) · 1.67 KB
/
uninstall
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
#!/usr/bin/env bash
usage() {
cat <<EOF
Usage: $0
This script will uninstall fzf-help from /usr/share/fzf-help. If you
want to uninstall without root privileges, use the --user option to uninstall
from ~/.local/share/fzf-help.
Options:
--root Uinstall from /usr/share/fzf-help (default)
--user Uninstall from ~/.local/share/fzf-help
-h, --help Show this help message
EOF
}
#######################################
# Parse command line arguments
#######################################
parse_args() {
while [[ $# -gt 0 ]]; do
case $1 in
--root)
shift
;;
--user)
plugin_dir="$HOME/.local/share/fzf-help"
shift
;;
-h | --help)
usage
exit 0
;;
*)
echo "Unknown option: $1"
usage
exit 1
;;
esac
done
}
abort() {
echo 'Uninstallation aborted'
exit 1
}
#######################################
# Remove old installation
#######################################
remove_old() {
remove="rm -rf $plugin_dir || abort"
if [[ -d $plugin_dir ]]; then
echo "Found old installation at: $plugin_dir"
echo "Deleting old installation..."
if [[ -w $plugin_dir ]]; then
echo 'Uninstall as user'
eval $remove
else
echo 'Uninstall as root'
eval "sudo $remove"
fi
echo 'Uninstall complete.'
else
echo "No old installation found at: $plugin_dir."
fi
}
plugin_dir=/usr/share/fzf-help
parse_args $@
remove_old