mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-08-19 05:31:05 +02:00
28958: Support registering hooks independent of the context.
This commit is contained in:
parent
15779b019d
commit
d7bcf2bb96
2 changed files with 19 additions and 4 deletions
|
@ -10,6 +10,9 @@
|
|||
|
||||
* unposted: ChangeLog: Fix typo in date.
|
||||
|
||||
* 28958: Functions/VCS_Info/VCS_INFO_hook: Support registering
|
||||
hooks independent of the context.
|
||||
|
||||
2011-03-29 Mikael Magnusson <mikachu@gmail.com>
|
||||
|
||||
* unposted: Completion/Unix/Command/_vim: Fix typo in
|
||||
|
@ -14399,5 +14402,5 @@
|
|||
|
||||
*****************************************************
|
||||
* This is used by the shell to define $ZSH_PATCHLEVEL
|
||||
* $Revision: 1.5235 $
|
||||
* $Revision: 1.5236 $
|
||||
*****************************************************
|
||||
|
|
|
@ -2,24 +2,36 @@
|
|||
## Written by Frank Terbeck <ft@bewatermyfriend.org>
|
||||
## Distributed under the same BSD-ish license as zsh itself.
|
||||
|
||||
local hook func
|
||||
local hook static func
|
||||
local -x context hook_name
|
||||
local -xi ret
|
||||
local -a hooks
|
||||
local -a hooks tmp
|
||||
local -i debug
|
||||
|
||||
ret=0
|
||||
hook_name="$1"
|
||||
shift
|
||||
context=":vcs_info:${vcs}+${hook_name}:${usercontext}:${rrn}"
|
||||
static=":vcs_info-static_hooks:${hook_name}"
|
||||
|
||||
zstyle -t "${context}" debug && debug=1 || debug=0
|
||||
if (( debug )); then
|
||||
printf 'VCS_INFO_hook: running hook: "%s"\n' "${hook_name}"
|
||||
printf 'VCS_INFO_hook: current context: "%s"\n' "${context}"
|
||||
printf 'VCS_INFO_hook: static context: "%s"\n' "${static}"
|
||||
fi
|
||||
|
||||
zstyle -a "${context}" hooks hooks || return 0
|
||||
zstyle -a "${static}" hooks hooks
|
||||
if (( debug )); then
|
||||
printf '+ static hooks: %s\n' "${(j:, :)hooks}"
|
||||
fi
|
||||
zstyle -a "${context}" hooks tmp
|
||||
if (( debug )); then
|
||||
printf '+ context hooks: %s\n' "${(j:, :)tmp}"
|
||||
fi
|
||||
hooks+=( "${tmp[@]}" )
|
||||
(( ${#hooks} == 0 )) && return 0
|
||||
|
||||
# Protect some internal variables in hooks. The `-g' parameter to
|
||||
# typeset does *not* make the parameters global here (they are already
|
||||
# "*-local-export). It prevents typeset from creating *new* *local*
|
||||
|
|
Loading…
Reference in a new issue