summary refs log tree commit diff
path: root/Functions/Misc
diff options
context:
space:
mode:
authorBart Schaefer <barts@users.sourceforge.net>2012-03-01 03:35:49 +0000
committerBart Schaefer <barts@users.sourceforge.net>2012-03-01 03:35:49 +0000
commitf2bf8fa36582e79361a1a961119a8ccb128bbb35 (patch)
tree3259e9de5ecab465175eef290385bd632c3389fd /Functions/Misc
parent30361b650cd85bdac90a22e0517844586124ae38 (diff)
downloadzsh-f2bf8fa36582e79361a1a961119a8ccb128bbb35.tar.gz
zsh-f2bf8fa36582e79361a1a961119a8ccb128bbb35.tar.xz
zsh-f2bf8fa36582e79361a1a961119a8ccb128bbb35.zip
unposted (30090): add -h (help) and -L (list extant hooks) options.
Diffstat (limited to 'Functions/Misc')
-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"