blob: fb12c4d25dcb01e4f1498c270a00bc2460bd76a2 (
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
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
|
## vim:ft=zsh
## Small function to help with git hooks
## Written 2008 by Daniel Friesel <derf@derf.homelinux.org>
autoload fdie
typeset hook_dir action=$1 hook=$2
if [[ -n $GIT_DIR && -d $GIT_DIR ]] {
hook_dir=$GIT_DIR/hooks
} elif [[ -d hooks ]] {
hook_dir=$PWD/hooks
} elif [[ -d .git/hooks ]] {
hook_dir=$PWD/.git/hooks
} elif [[ $PWD == */hooks ]] {
hook_dir=$PWD
} else {
fdie 'No git or hook directory found.'; return
}
function usage {
cat <<- ENDOFHELP
Usage: git-hook enable|disable <hook>
ENDOFHELP
}
if [[ $#* < 1 ]] {
usage; return
}
function hook_enable {
if [[ -e $hook_dir/$hook ]] {
if ! [[ -x $hook_dir/$hook ]] {
chmod u+x $hook_dir/$hook
}
} else {
fdie "No such hook: '$hook'"; return
}
}
function hook_disable {
if [[ -e $hook_dir/$hook ]] {
if [[ -x $hook_dir/$hook ]] {
chmod u-x $hook_dir/$hook
}
} else {
fdie "No such hook: '$hook'"; return
}
}
function hook_list {
for hook in $hook_dir/*; {
[[ -x $hook ]] && echo -n $green
echo -n ${hook:t}
echo $reset
}
}
case $action in
enable) shift 2; hook_enable $* ;;
disable) shift 2; hook_disable $* ;;
list) shift; hook_list $* ;;
*) usage ;;
esac
|