From f2bf8fa36582e79361a1a961119a8ccb128bbb35 Mon Sep 17 00:00:00 2001 From: Bart Schaefer Date: Thu, 1 Mar 2012 03:35:49 +0000 Subject: unposted (30090): add -h (help) and -L (list extant hooks) options. --- Functions/Misc/add-zsh-hook | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'Functions') 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" -- cgit 1.4.1