summary refs log tree commit diff
path: root/Functions
diff options
context:
space:
mode:
Diffstat (limited to 'Functions')
-rw-r--r--Functions/Misc/add-zsh-hook22
1 files changed, 17 insertions, 5 deletions
diff --git a/Functions/Misc/add-zsh-hook b/Functions/Misc/add-zsh-hook
index c49688643..ee37d674d 100644
--- a/Functions/Misc/add-zsh-hook
+++ b/Functions/Misc/add-zsh-hook
@@ -19,12 +19,13 @@ hooktypes=(
   chpwd precmd preexec periodic zshaddhistory zshexit
   zsh_directory_name
 )
+local usage="Usage: $0 hook function\nValid hooks are:\n  $hooktypes"
 
 local opt
 local -a autoopts
-integer del
+integer del list help
 
-while getopts "dDUzk" opt; do
+while getopts "dDhLUzk" opt; do
   case $opt in
     (d)
     del=1
@@ -34,6 +35,14 @@ while getopts "dDUzk" opt; do
     del=2
     ;;
 
+    (h)
+    help=1
+    ;;
+
+    (L)
+    list=1
+    ;;
+
     ([Uzk])
     autoopts+=(-$opt)
     ;;
@@ -45,9 +54,12 @@ while getopts "dDUzk" opt; do
 done
 shift $(( OPTIND - 1 ))
 
-if (( $# != 2 || ${hooktypes[(I)$1]} == 0 )); then
-  print "Usage: $0 hook function\nValid hooks are:\n  $hooktypes"
-  return 1
+if (( list )); then
+  typeset -mp "(${1:-${(@j:|:)hooktypes}})_functions"
+  return $?
+elif (( help || $# != 2 || ${hooktypes[(I)$1]} == 0 )); then
+  print -u$(( 2 - help )) $usage
+  return $(( 1 - help ))
 fi
 
 local hook="${1}_functions"