Add zsh-lookup sub-system
[grml-etc-core.git] / usr_share_grml / zsh / functions / Lookup / LOOKUP_hook
1 ### vim:ft=zsh:foldmethod=marker
2 ## run hooks
3 ## Copyright: 2009, Frank Terbeck <ft@bewatermyfriend.org>
4
5 LOOKUP_guard || return 1
6 local hook obackend old_lookup_ei ret lookup_context
7 local -a hooks
8
9 lookup_context="$(LOOKUP_context)"
10
11 obackend="${backend}"
12 if [[ $1 != '--' ]] ; then
13     backend="$1"
14 fi
15 shift
16
17 zstyle -t "${lookup_context}" debug &&
18     printf 'LOOKUP_hook: current context: "%s"\n' "${lookup_context}"
19
20 zstyle -a "${lookup_context}" hooks hooks || return 0
21
22 old_lookup_ei=${lookup_ei}
23 lookup_ei='-hook-'
24 for hook in ${hooks} ; do
25     (( ${+functions[$hook]} == 0 )) && continue
26     ${hook} "$@"
27     case $? in
28         (1)
29             break
30             ;;
31         (0|*)
32             ;;
33     esac
34 done
35 lookup_ei="${old_lookup_ei}"
36 backend="${obackend}"
37 return 0