-
Notifications
You must be signed in to change notification settings - Fork 0
/
zman.zsh
executable file
·78 lines (63 loc) · 1.14 KB
/
zman.zsh
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
#!/usr/bin/env zsh
zman() {
readonly ZMAN_HOME="${ZMAN_HOME:-"$HOME/.zman"}"
readonly ZMAN_LIB=$ZMAN_HOME/lib
help() {
cat $ZMAN_HOME/help.txt
}
init() {
# source all the files in `lib`
source <(cat "$ZMAN_LIB"/*.zsh)
}
add() {
git submodule add --progress "$@"
}
update() {
git submodule foreach --recursive git pull
}
remove() {
for module in "$@"; do
git submodule deinit --force "$module"
git rm -fr "$module"
rm -rf .git/modules/"$module"
done
}
use() {
if [ -f "$ZMAN_HOME/$1" ]; then
source "$ZMAN_HOME"/"$1"
else
echo "$module doesn't exist, please add it"
fi
}
case "$1" in
u|update)
( cd "$ZMAN_HOME" && update 1> /dev/null )
;;
a|add)
shift
( cd "$ZMAN_HOME" && add "$@" 1> /dev/null )
;;
r|remove)
shift
( cd "$ZMAN_HOME" && remove "$@" 1> /dev/null )
;;
use)
shift
use "$@"
;;
init)
init
;;
help|*)
help
;;
esac
unfunction update
unfunction add
unfunction remove
unfunction use
unfunction init
unfunction help
}
# check if we're being sourced and if true, start to initilize zman
[[ $ZSH_EVAL_CONTEXT =~ :file$ ]] && zman init