forked from mzp/Git-Hooks
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit-hooks-completion.zsh
94 lines (73 loc) · 1.83 KB
/
git-hooks-completion.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!zsh
_git-hooks ()
{
local curcontext="$curcontext" state line
typeset -A opt_args
_arguments -C \
':command:->command' \
'*::options:->options'
case $state in
(command)
local -a subcommands
subcommands=(
'list:list'
'enabled:enabled'
'disabled:disabled'
'on:on'
'off:off'
'update:update'
)
_describe -t commands 'git hooks' subcommands
;;
(options)
case $line[1] in
(list)
;;
(enabled)
;;
(disabled)
;;
(on)
__git-hooks-on/off
;;
(off)
__git-hooks-on/off
;;
(update)
_arguments \
':remote:__git_remotes'\
;;
esac
;;
esac
}
__git-hooks-on/off ()
{
local expl
declare -a hooks
hooks=(${${(f)"$(_call_program hooks git hooks list 2> /dev/null)"}})
__git_command_successful || return
_wanted hooks expl 'hooks' compadd $hooks
}
__git_remotes() {
local expl
declare -a remotes
remotes=(${${(f)"$(_call_program remote git --git-dir=$GIT_HOOKS_HOME/.git for-each-ref --format='"%(refname)"' refs/remotes 2>/dev/null)"}#refs/remotes/})
__git_command_successful || return
_wanted remotes expl 'remotes' compadd $remotes
}
__git_branch_names () {
local expl
declare -a branch_names
branch_names=(${${(f)"$(_call_program branchrefs git --git-dir=$GIT_HOOKS_HOME/.git for-each-ref --format='"%(refname)"' refs/heads 2>/dev/null)"}#refs/heads/})
__git_command_successful || return
_wanted branch-names expl branch-name compadd $* - $branch_names
}
__git_command_successful () {
if (( ${#pipestatus:#0} > 0 )); then
_message 'not a git repository'
return 1
fi
return 0
}
zstyle ':completion:*:*:git:*' user-commands hooks:'Git-Hooks manage command'