1## vim:ft=zsh
2## Written by Frank Terbeck <ft@bewatermyfriend.org>
3## Distributed under the same BSD-ish license as zsh itself.
4
5emulate -L zsh
6setopt extendedglob
7
8local -i all
9
10if [[ "x$1" == 'x-a' ]]; then
11    all=1
12    shift
13else
14    all=0
15fi
16
17if (( ${#argv} < 2 )); then
18    print 'usage: vcs_info_hookdel [-a] <HOOK> <FUNCTION(s)...>'
19    return 1
20fi
21
22local hook func context
23local -a old
24
25hook=$1
26shift
27context=":vcs_info-static_hooks:${hook}"
28
29zstyle -a "${context}" hooks old || return 0
30for func in "$@"; do
31    if [[ -n ${(M)old:#$func} ]]; then
32        old[(Re)$func]=()
33    else
34        printf 'Not statically registered to `%s'\'': "%s"\n' \
35            "${hook}" "${func}"
36        continue
37    fi
38    if (( all )); then
39        while [[ -n ${(M)old:#$func} ]]; do
40            old[(Re)$func]=()
41        done
42    fi
43done
44zstyle "${context}" hooks "${old[@]}"
45return $?
46