summaryrefslogtreecommitdiff
path: root/Functions/Misc/add-zsh-hook
diff options
context:
space:
mode:
Diffstat (limited to 'Functions/Misc/add-zsh-hook')
-rw-r--r--Functions/Misc/add-zsh-hook15
1 files changed, 13 insertions, 2 deletions
diff --git a/Functions/Misc/add-zsh-hook b/Functions/Misc/add-zsh-hook
index b11db5b5c..d349ac635 100644
--- a/Functions/Misc/add-zsh-hook
+++ b/Functions/Misc/add-zsh-hook
@@ -4,6 +4,9 @@
#
# 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
@@ -18,12 +21,16 @@ local opt
local -a autoopts
integer del
-while getopts "d" opt; do
+while getopts "dDU" opt; do
case $opt in
(d)
del=1
;;
+ (D)
+ del=2
+ ;;
+
(U)
autoopts+=(-$opt)
;;
@@ -46,7 +53,11 @@ local fn="$2"
if (( del )); then
# delete, if hook is set
if (( ${(P)+hook} )); then
- set -A $hook ${(P)hook:#$fn}
+ if (( del == 2 )); then
+ set -A $hook ${(P)hook:#${~fn}}
+ else
+ set -A $hook ${(P)hook:#$fn}
+ fi
# unset if no remaining entries --- this can give better
# performance in some cases
(( ${(P)#hook} )) || unset $hook