Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: custom zsh hooks (was Re: Extending zsh hooks)



On Tue, Nov 07, 2023 at 09:35:30PM -0500, Lawrence Velázquez wrote:
[...]
> The usual process is to propose changes on this list and include
> any patches inline or as an attachment.  You can find many examples
> in the archive (e.g., <https://www.zsh.org/mla/workers/2023/>).

Perfect! My one-line-plus-documentation patch is below. The proposal is to
have a way to add custom hook types to be managed with add-zsh-hook.

> -- 
> vq
--Gregory

diff --git a/Doc/Zsh/contrib.yo b/Doc/Zsh/contrib.yo
index f43ac2257..004a244b6 100644
--- a/Doc/Zsh/contrib.yo
+++ b/Doc/Zsh/contrib.yo
@@ -303,10 +303,11 @@ The shell function tt(add-zsh-hook) provides a simple way of adding or
 removing functions from the array.
 
 var(hook) is one of tt(chpwd), tt(periodic), tt(precmd), tt(preexec),
-tt(zshaddhistory), tt(zshexit), or tt(zsh_directory_name),
-the special functions in question.  Note that tt(zsh_directory_name)
-is called in a different way from the other functions, but may
-still be manipulated as a hook.
+tt(zshaddhistory), tt(zshexit), or tt(zsh_directory_name), the special
+functions in question.  Additional custom hooks may be manipulated with
+add-zsh-hook by setting the var(customhooktypes) shell variable.  Note that
+tt(zsh_directory_name) is called in a different way from the other
+functions, but may still be manipulated as a hook.
 
 var(function) is name of an ordinary shell function.  If no options
 are given this will be added to the array of functions to be executed
diff --git a/Functions/Misc/add-zsh-hook b/Functions/Misc/add-zsh-hook
index 3bc952e2f..33090f201 100644
--- a/Functions/Misc/add-zsh-hook
+++ b/Functions/Misc/add-zsh-hook
@@ -18,6 +18,7 @@ local -a hooktypes
 hooktypes=(
   chpwd precmd preexec periodic zshaddhistory zshexit
   zsh_directory_name
+  ${customhooktypes:-}
 )
 local usage="Usage: add-zsh-hook hook function\nValid hooks are:\n  $hooktypes"
 




Messages sorted by: Reverse Date, Date, Thread, Author