-
Notifications
You must be signed in to change notification settings - Fork 311
/
Copy pathm
executable file
·71 lines (51 loc) · 1.25 KB
/
m
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
#!/usr/bin/env bash
[ -L $0 ] && pushd `readlink $0 | xargs dirname` > /dev/null \
|| pushd `dirname $0` > /dev/null
export MPATH=`pwd -P`
popd > /dev/null
confirm () {
read -r -p "${1:-Are you sure? [y/N]} " response
case $response in
[yY][eE][sS]|[yY])
true
;;
*)
false
;;
esac
}
update_mcli(){
INSTALL_DIR=${MPATH} ${MPATH}/install.sh
}
uninstall_mcli(){
confirm "Do you want to uninstall m-cli? [y/n]: " \
&& sudo rm -rf ${MPATH} 2>/dev/null \
&& sudo rm -f "/usr/local/bin/m" 2>/dev/null \
&& echo "Done !"
}
usage(){
cat <<__EOF__
Swiss Army Knife for macOS !
usage: m [OPTIONS] COMMAND [help]
OPTIONS
--update update m-cli to the latest version
--uninstall uninstall m-cli
COMMANDS:
help
__EOF__
for i in ${MPATH}/plugins/*; do
[ ! -L "$i" -a -f "$i" ] && echo " ${i##*/}"
done
[ "${COMMAND}" == "help" ] && exit 0 || exit 1
}
case $1 in
--update)
update_mcli && exit 0
;;
--uninstall)
uninstall_mcli && exit 0
;;
esac
COMMAND=$1; shift;
[ ! -f ${MPATH}/plugins/${COMMAND} ] && usage
${MPATH}/plugins/${COMMAND} "$@"