diff options
Diffstat (limited to 'Functions/Misc')
-rw-r--r-- | Functions/Misc/add-zsh-hook | 22 | ||||
-rw-r--r-- | Functions/Misc/promptnl | 2 | ||||
-rw-r--r-- | Functions/Misc/zargs | 16 | ||||
-rw-r--r-- | Functions/Misc/zkbd | 15 |
4 files changed, 34 insertions, 21 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" diff --git a/Functions/Misc/promptnl b/Functions/Misc/promptnl index a98c4b8ee..155d58770 100644 --- a/Functions/Misc/promptnl +++ b/Functions/Misc/promptnl @@ -62,7 +62,7 @@ done # If the cursor is not in the first column, emit EOLMARK and newline. -(( ${${RECV#*\;}%R} > 1 )) && print -P -- $EOLMARK +(( ${${${RECV#*\;}%R}:-0} > 1 )) && print -P -- $EOLMARK return 0 diff --git a/Functions/Misc/zargs b/Functions/Misc/zargs index 8350b1aba..71fd42835 100644 --- a/Functions/Misc/zargs +++ b/Functions/Misc/zargs @@ -167,14 +167,14 @@ if [[ $eof == -(e|-eof) ]]; then ((end=ARGC+1)) elif (( $#eof )); then end=$argv[(i)${eof##-(e|-eof=)}] else end=$argv[(i)--] fi -local -a args call command; command=( ${argv[end+1,-1]} ) +local -a args call command; command=( "${(@)argv[end+1,-1]}" ) if (( $opts[(I)-(null|0)] )) -then set -- ${(ps:\000:)argv[1,end-1]} -else set -- $argv[1,end-1] +then set -- "${(@ps:\000:)argv[1,end-1]}" +else set -- "${(@)argv[1,end-1]}" fi -if [[ -n $command ]] +if (( $#command )) then (( c = $#command - 1 )) else command=( print -r -- ) fi @@ -187,7 +187,7 @@ local execute=' then print -u2 -r -- "$call" fi eval "{ - \$call + \"\${(@)call}\" } $bg"' local ret=0 analyze=' case $? in @@ -275,11 +275,11 @@ do ((ARGC)) || break for (( end=l; end && ${(c)#argv[1,end]} > s; end/=2 )) { } (( end > n && ( end = n ) )) - args=( $argv[1,end] ) + args=( "${(@)argv[1,end]}" ) shift $((end > ARGC ? ARGC : end)) if (( $#i )) - then call=( ${command/$i/$args} ) - else call=( $command $args ) + then call=( "${(@)command/$i/$args}" ) + else call=( "${(@)command}" "${(@)args}" ) fi if (( ${(c)#call} > s )) then diff --git a/Functions/Misc/zkbd b/Functions/Misc/zkbd index a28354b07..1065a84f1 100644 --- a/Functions/Misc/zkbd +++ b/Functions/Misc/zkbd @@ -14,8 +14,7 @@ local zkbd term key seq zkbd=${ZDOTDIR:-$HOME}/.zkbd [[ -d $zkbd ]] || mkdir $zkbd || return 1 -print 'typeset -g -A key\n' > $zkbd/$TERM.tmp || return 1 -trap "unfunction getmbkey getseq; command rm -f $zkbd/$TERM.tmp" 0 +trap 'unfunction getmbkey getseq; command rm -f $zkbd/$TERM.tmp' 0 trap "return 1" 1 2 15 getmbkey () { @@ -57,6 +56,7 @@ getseq () { read term"?Enter current terminal type: [$TERM] " [[ -n $term ]] && TERM=$term +print 'typeset -g -A key\n' > $zkbd/$TERM.tmp || return 1 cat <<\EOF @@ -251,21 +251,22 @@ else fi fi -local termID=${DISPLAY:-$VENDOR-$OSTYPE} -command mv $zkbd/$TERM.tmp $zkbd/$TERM-$termID +local termID=${${DISPLAY:t}:-$VENDOR-$OSTYPE} termFile=$zkbd/$TERM.tmp +command mv $termFile $zkbd/$TERM-$termID && termFile=$zkbd/$TERM-$termID cat <<EOF Parameter assignments for the keys you typed have been written to the file: -$zkbd/$TERM-$termID +$termFile You may read this file into ${ZDOTDIR:-$HOME}/.zshrc or another startup file with the "source" or "." commands, then reference the \$key parameter -in bindkey commands, like this: +in bindkey commands, for example like this: - source ${zkbd/$HOME/~}/\$TERM-\${DISPLAY:-\$VENDOR-\$OSTYPE} + source ${(D)zkbd}/\$TERM-\${\${DISPLAY:t}:-\$VENDOR-\$OSTYPE} [[ -n \${key[Left]} ]] && bindkey "\${key[Left]}" backward-char [[ -n \${key[Right]} ]] && bindkey "\${key[Right]}" forward-char # etc. +Adjust the name of the file being sourced, as necessary. EOF |