summaryrefslogtreecommitdiff
path: root/etc/completions/_git-hook
blob: cdf15a7b0456874ef4ab451d8281eb54428f5093 (plain)
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
#compdef git-hook
## Completion for the git-hook function, see ../functions/git-hook
## Copyright (C) 2008 by Daniel Friesel <derf@derf.homelinux.org>
## License: WTFPL <http://sam.zoy.org/wtfpl>

typeset hook_dir expl

if [[ -n $GIT_DIR && -d $GIT_DIR ]] {
	hook_dir=$GIT_DIR/hooks
} elif [[ -d .git/hooks ]] {
	hook_dir=$PWD/.git/hooks
} elif [[ -d hooks ]] {
	hook_dir=$PWD/hooks
} elif [[ $PWD == */hooks ]] {
	hook_dir=$PWD
} else {
	hook_dir=$(git rev-parse --git-dir)/hooks
}

if (( CURRENT == 2 )) {
	_wanted ation expl 'action' \
	compadd list enable disable
} elif (( CURRENT == 3 )) {
	if [[ ${words[2]} == 'enable' ]] {
		_wanted hook expl 'git hook' \
		_path_files -W $hook_dir -g '*(^x)'
	} elif [[ ${words[2]} == 'disable' ]] {
		_wanted hook expl 'git hook' \
		_path_files -W $hook_dir -g '*(x)'
	}
}