Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

unposted (30090): add -h (help) and -L (list extant hooks) options.

  • Loading branch information...
commit f2bf8fa36582e79361a1a961119a8ccb128bbb35 1 parent 30361b6
Bart Schaefer authored
Showing with 17 additions and 5 deletions.
  1. +17 −5 Functions/Misc/add-zsh-hook
View
22 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"
Please sign in to comment.
Something went wrong with that request. Please try again.