summaryrefslogtreecommitdiff
path: root/Functions/Misc/add-zsh-hook
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2008-07-17 11:27:55 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2008-07-17 11:27:55 +0000
commit0409391c7d08016de3f1ea8b1a74d5856669ffaa (patch)
tree08c73dd57ba775e380384f3b408cfda4446c1861 /Functions/Misc/add-zsh-hook
parent4f7cf022b6963985a75c5a00ef59c7168551b225 (diff)
downloadzsh-0409391c7d08016de3f1ea8b1a74d5856669ffaa.tar.gz
zsh-0409391c7d08016de3f1ea8b1a74d5856669ffaa.zip
25272: add zshaddhistory hook
Diffstat (limited to 'Functions/Misc/add-zsh-hook')
-rw-r--r--Functions/Misc/add-zsh-hook20
1 files changed, 11 insertions, 9 deletions
diff --git a/Functions/Misc/add-zsh-hook b/Functions/Misc/add-zsh-hook
index d349ac635..f534980f5 100644
--- a/Functions/Misc/add-zsh-hook
+++ b/Functions/Misc/add-zsh-hook
@@ -1,27 +1,27 @@
# Add to HOOK the given FUNCTION.
-# HOOK is one of chpwd, precmd, preexec, periodic, zshexit (the
-# _functions subscript is not required).
+# HOOK is one of chpwd, precmd, preexec, periodic, zshaddhistory,
+# zshexit (the _functions subscript is not required).
#
# With -d, remove the function from the hook instead; delete the hook
# variable if it is empty.
-#
+#
# -D behaves like -d, but pattern characters are active in the
# function name, so any matching function will be deleted from the hook.
#
# Without -d, the FUNCTION is marked for autoload; -U is passed down to
-# autoload if that is given. (This is harmless if the function is actually
-# defined inline.)
+# autoload if that is given, as are -z and -k. (This is harmless if the
+# function is actually defined inline.)
emulate -L zsh
local -a hooktypes
-hooktypes=(chpwd precmd preexec periodic zshexit)
+hooktypes=(chpwd precmd preexec periodic zshaddhistory zshexit)
local opt
local -a autoopts
integer del
-while getopts "dDU" opt; do
+while getopts "dDUzk" opt; do
case $opt in
(d)
del=1
@@ -31,7 +31,7 @@ while getopts "dDU" opt; do
del=2
;;
- (U)
+ ([Uzk])
autoopts+=(-$opt)
;;
@@ -60,7 +60,9 @@ if (( del )); then
fi
# unset if no remaining entries --- this can give better
# performance in some cases
- (( ${(P)#hook} )) || unset $hook
+ if (( ! ${(P)#hook} )); then
+ unset $hook
+ fi
fi
else
if (( ${(P)+hook} )); then