-
Notifications
You must be signed in to change notification settings - Fork 3
/
_updatelocal
58 lines (54 loc) · 1.86 KB
/
_updatelocal
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
#compdef updatelocal
local state ret=1
typeset -A opt_args
typeset -a commands
commands=(
-r:'Completely reset supplied git directory basename and pull latest changes from remote repo, resets current directory if basename not supplied'
-p:'Set $UPDATELOCAL_GITDIR to the current directory temporarily and run'
-c:'show a log of all repos with changes which have not been pulled yet'
-h:'show this extremely helpful text'
)
_arguments -C \
'1: :->command'\
'*: :->argument' && ret=0
case $state in
command)
_describe -t commands "option" commands && ret=0
;;
argument)
[[ $words[2] = -p || $words[2] = --pwd ]] && {
local UPDATELOCAL_GITDIR=$PWD
local UL_pending=
words[2]=()
}
case $words[2] in
-r)
typeset -a gitdirs
gitdirs=( "$UPDATELOCAL_GITDIR/"/*(N:t) )
[[ -r $TMPDIR/updatelocal_pending ]] && source $TMPDIR/updatelocal_pending
if [[ -n $UL_pending ]]; then
typeset -a pending
pending=( ${UL_pending[@]} )
_alternative \
'pending:Pending:compadd -a - pending' \
'gitdirs:Repos:compadd -a - gitdirs' && \
ret=0
else
_wanted gitdirs expl "Repos" \
compadd "$@" -a - gitdirs && ret=0
fi
;;
-c)
if [[ -n $UL_pending ]]; then
typeset -a pending
pending=( ${UL_pending[@]} )
_wanted pending expl "Pending" \
compadd "$@" -a - UL_pending && ret=0
fi
;;
*)
ret=1
;;
esac
esac
return "$ret"