diff options
author | Axel Beckert <abe@deuxchevaux.org> | 2012-07-22 21:40:10 +0200 |
---|---|---|
committer | Axel Beckert <abe@deuxchevaux.org> | 2012-07-22 21:40:10 +0200 |
commit | 5c7ac461932c17df91374e6c2740ad22c95481af (patch) | |
tree | 85d21004331d9d1bfca266d111000acd7fa1725a /Functions | |
parent | 3988419a8dc4a74e491df584804a77a2f8be88cd (diff) | |
parent | e27142d45686cacc6ed155e5045b97dd6243d44c (diff) | |
download | zsh-5c7ac461932c17df91374e6c2740ad22c95481af.tar.gz zsh-5c7ac461932c17df91374e6c2740ad22c95481af.zip |
New upstream release
Diffstat (limited to 'Functions')
-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 | ||||
-rw-r--r-- | Functions/Prompts/prompt_fade_setup | 2 | ||||
-rw-r--r-- | Functions/Prompts/promptinit | 1 | ||||
-rw-r--r-- | Functions/VCS_Info/Backends/VCS_INFO_get_data_git | 2 | ||||
-rw-r--r-- | Functions/VCS_Info/vcs_info_setsys | 1 | ||||
-rw-r--r-- | Functions/Zftp/zfcd_match | 1 | ||||
-rw-r--r-- | Functions/Zle/forward-word-match | 36 | ||||
-rw-r--r-- | Functions/Zle/replace-string | 9 | ||||
-rw-r--r-- | Functions/Zle/select-word-style | 138 | ||||
-rw-r--r-- | Functions/Zle/split-shell-arguments | 2 | ||||
-rw-r--r-- | Functions/Zle/url-quote-magic | 5 |
14 files changed, 144 insertions, 108 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 diff --git a/Functions/Prompts/prompt_fade_setup b/Functions/Prompts/prompt_fade_setup index 0b433dc48..d915cc0de 100644 --- a/Functions/Prompts/prompt_fade_setup +++ b/Functions/Prompts/prompt_fade_setup @@ -31,7 +31,7 @@ prompt_fade_setup () { autoload -Uz prompt_special_chars prompt_special_chars - PS1="%F{$fadebar_cwd}%B%K{$fadebar_cwd}$schars[333]$schars[262]$schars[261]$schars[260]%F{$userhost}%K{$fadebar_cwd}%B%n@%m%b%F{$fadebar_cwd}%K{black}$schars[333]$schars[262]$schars[261]$schars[260]%F{$date}%K{black}%B %D{%a %b %d} %D{%I:%M:%S%P} $prompt_newline%F{fadebar_cwd}%K{black}%B%~/%b%k%f " + PS1="%F{$fadebar_cwd}%B%K{$fadebar_cwd}$schars[333]$schars[262]$schars[261]$schars[260]%F{$userhost}%K{$fadebar_cwd}%B%n@%m%b%F{$fadebar_cwd}%K{black}$schars[333]$schars[262]$schars[261]$schars[260]%F{$date}%K{black}%B %D{%a %b %d} %D{%I:%M:%S%P} $prompt_newline%F{$fadebar_cwd}%K{black}%B%~/%b%k%f " PS2="%F{$fadebar_cwd}%K{black}$schars[333]$schars[262]$schars[261]$schars[260]%f%k>" prompt_opts=(cr subst percent) diff --git a/Functions/Prompts/promptinit b/Functions/Prompts/promptinit index 66e73a7a5..edf2d028b 100644 --- a/Functions/Prompts/promptinit +++ b/Functions/Prompts/promptinit @@ -15,6 +15,7 @@ promptinit () { emulate -L zsh setopt extendedglob local ppath='' name theme + local -a match mbegin mend # Autoload all prompt_*_setup functions in fpath for theme in $^fpath/prompt_*_setup(N); do diff --git a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git index 01bf9f3f5..9364fd021 100644 --- a/Functions/VCS_Info/Backends/VCS_INFO_get_data_git +++ b/Functions/VCS_Info/Backends/VCS_INFO_get_data_git @@ -134,7 +134,7 @@ if [[ -d $patchdir ]] ; then stgit_applied=(${(f)"$(< "${patchdir}/applied")"}) stgit_applied=( ${(Oa)stgit_applied} ) stgit_unapplied=(${(f)"$(< "${patchdir}/unapplied")"}) - stgit_unapplied=( ${(oa)stgit_applied} ) + stgit_unapplied=( ${(oa)stgit_unapplied} ) if VCS_INFO_hook 'gen-applied-string' "${stgit_applied[@]}"; then if (( ${#stgit_applied} )); then diff --git a/Functions/VCS_Info/vcs_info_setsys b/Functions/VCS_Info/vcs_info_setsys index 1484464ce..a4c3036be 100644 --- a/Functions/VCS_Info/vcs_info_setsys +++ b/Functions/VCS_Info/vcs_info_setsys @@ -7,6 +7,7 @@ setopt extendedglob typeset_silent local sys typeset -ga VCS_INFO_backends +local -a match mbegin mend VCS_INFO_backends=() diff --git a/Functions/Zftp/zfcd_match b/Functions/Zftp/zfcd_match index 16de5c81c..95de4c583 100644 --- a/Functions/Zftp/zfcd_match +++ b/Functions/Zftp/zfcd_match @@ -13,6 +13,7 @@ local ZFTP_VERBOSE=45 # should we redirect 2>/dev/null or let the user see it? local tmpf=${TMPPREFIX}zfcm$$ +local -a match mbegin mend if [[ $ZFTP_SYSTEM = UNIX* ]]; then # hoo, aren't we lucky: this makes things so much easier diff --git a/Functions/Zle/forward-word-match b/Functions/Zle/forward-word-match index 50e18cbde..e5b5ef3a6 100644 --- a/Functions/Zle/forward-word-match +++ b/Functions/Zle/forward-word-match @@ -8,32 +8,36 @@ local -a matched_words integer count=${NUMERIC:-1} if (( count < 0 )); then - (( NUMERIC = -count )) - zle ${WIDGET/forward/backward} - return + (( NUMERIC = -count )) + zle ${WIDGET/forward/backward} + return fi while (( count-- )); do - - match-words-by-style - + match-words-by-style + + if zstyle -t $curcontext skip-whitespace-first; then + # Standard non-zsh behaviour: skip leading whitespace and the word. + word=$matched_words[4]$matched_words[5] + else + # Traditional zsh behaviour. # For some reason forward-word doesn't work like the other word # commands; it skips whitespace only after any matched word # characters. - if [[ -n $matched_words[4] ]]; then - # just skip the whitespace - word=$matched_words[4] + # just skip the whitespace + word=$matched_words[4] else - # skip the word and trailing whitespace - word=$matched_words[5]$matched_words[6] + # skip the word and trailing whitespace + word=$matched_words[5]$matched_words[6] fi + fi - if [[ -n $word ]]; then - (( CURSOR += ${#word} )) - else - return 1 - fi + if [[ -n $word ]]; then + (( CURSOR += ${#word} )) + else + return 1 + fi done return 0 diff --git a/Functions/Zle/replace-string b/Functions/Zle/replace-string index a3416a403..68aac28d2 100644 --- a/Functions/Zle/replace-string +++ b/Functions/Zle/replace-string @@ -4,6 +4,9 @@ setopt extendedglob autoload -Uz read-from-minibuffer replace-string-again local p1 p2 +integer changeno=$UNDO_CHANGE_NO + +{ if [[ -n $_replace_string_src ]]; then p1="[$_replace_string_src -> $_replace_string_rep]"$'\n' @@ -30,4 +33,10 @@ if [[ -n $REPLY ]]; then typeset -g _replace_string_rep=$REPLY fi +} always { + # Undo back to the original line; we don't want the + # undo history of editing the strings left. + zle undo $changeno +} + replace-string-again $curwidget diff --git a/Functions/Zle/select-word-style b/Functions/Zle/select-word-style index 95d2e4446..1e472229c 100644 --- a/Functions/Zle/select-word-style +++ b/Functions/Zle/select-word-style @@ -4,71 +4,75 @@ setopt extendedglob local -a word_functions word_functions=(backward-kill-word backward-word - capitalize-word down-case-word - forward-word kill-word - transpose-words up-case-word) + capitalize-word down-case-word + forward-word kill-word + transpose-words up-case-word) [[ -z $1 ]] && autoload -Uz read-from-minibuffer -local REPLY detail f wordstyle +local REPLY detail f wordstyle teststyle if ! zle -l $word_functions[1]; then - for f in $word_functions; do - autoload -Uz $f-match - zle -N $f $f-match - done + for f in $word_functions; do + autoload -Uz $f-match + zle -N $f $f-match + done fi while true; do - - if [[ -n $WIDGET && -z $1 ]]; then - read-from-minibuffer -k1 "Word styles (hit return for more detail): + if [[ -n $WIDGET && -z $1 ]]; then + read-from-minibuffer -k1 "Word styles (hit return for more detail): (b)ash (n)ormal (s)hell (w)hitespace (d)efault (q)uit (B), (N), (S), (W) as above with subword matching ${detail}? " || return 1 - else - REPLY=$1 - fi - - detail= - - case $REPLY in - ([bB]*) - # bash style - wordstyle=standard - zstyle ':zle:*' word-chars '' - ;; - - ([nN]*) - # normal zsh style - wordstyle=standard - zstyle ':zle:*' word-chars "$WORDCHARS" - ;; - - ([sS]*) - # shell command arguments or special tokens - wordstyle=shell - ;; - - ([wW]*) - # whitespace-delimited - wordstyle=space - ;; - - (d*) - # default: could also return widgets to builtins here - wordstyle= - zstyle -d ':zle:*' word-chars - ;; - - (q*) - # quit without setting - return 1 - ;; - - (*) - detail="\ + else + REPLY=$1 + fi + + detail= + + case $REPLY in + ([bB]*) + # bash style + wordstyle=standard + zstyle ':zle:*' word-chars '' + zstyle ':zle:*' skip-whitespace-first true + ;; + + ([nN]*) + # normal zsh style + wordstyle=standard + zstyle ':zle:*' word-chars "$WORDCHARS" + zstyle ':zle:*' skip-whitespace-first false + ;; + + ([sS]*) + # shell command arguments or special tokens + wordstyle=shell + zstyle ':zle:*' skip-whitespace-first false + ;; + + ([wW]*) + # whitespace-delimited + wordstyle=space + zstyle ':zle:*' skip-whitespace-first false + ;; + + (d*) + # default: could also return widgets to builtins here + wordstyle= + zstyle -d ':zle:*' word-chars + zstyle -d ':zle:*' skip-whitespace-first + ;; + + (q*) + # quit without setting + return 1 + ;; + + (*) + detail="\ (b)ash: Word characters are alphanumerics only (n)ormal: Word characters are alphanumerics plus \$WORDCHARS (s)hell: Words are command arguments using shell syntax @@ -76,21 +80,21 @@ ${detail}? " || return 1 (d)efault: Use default, no special handling (usually same as \`n') (q)uit: Quit without setting a new style " - if [[ -z $WIDGET || -n $1 ]]; then - print "Usage: $0 word-style + if [[ -z $WIDGET || -n $1 ]]; then + print "Usage: $0 word-style where word-style is one of the characters in parentheses: $detail" >&2 - return 1 - fi - continue - ;; - esac - - if [[ -n $wordstyle ]]; then - if [[ $REPLY = [[:upper:]]* ]]; then - wordstyle+=-subword - fi - zstyle ':zle:*' word-style $wordstyle + return 1 + fi + continue + ;; + esac + + if [[ -n $wordstyle ]]; then + if [[ $REPLY = [[:upper:]]* ]]; then + wordstyle+=-subword fi - return + zstyle ':zle:*' word-style $wordstyle + fi + return done diff --git a/Functions/Zle/split-shell-arguments b/Functions/Zle/split-shell-arguments index 32b04fcb5..11a928719 100644 --- a/Functions/Zle/split-shell-arguments +++ b/Functions/Zle/split-shell-arguments @@ -17,6 +17,7 @@ integer pos=1 cpos=$((CURSOR+1)) opos iword ichar bufwords=(${(Z+n+)BUFFER}) +typeset -ga reply reply=() while [[ ${BUFFER[pos]} = [[:space:]] ]]; do (( pos++ )) @@ -44,6 +45,7 @@ for word in "${bufwords[@]}"; do fi done +typeset -g REPLY REPLY2 if (( iword == 0 )); then # At the end of the line, so off the indexable positions # (but still a valid cursor position). diff --git a/Functions/Zle/url-quote-magic b/Functions/Zle/url-quote-magic index c7bb88c5d..fbcc7c19c 100644 --- a/Functions/Zle/url-quote-magic +++ b/Functions/Zle/url-quote-magic @@ -60,7 +60,7 @@ # Use compsys for nested quoting analysis and command parsing. # Establish default values for styles, but only if not already set -local -a reply +local -a reply match mbegin mend zstyle -m ':url-quote-magic:\*' url-metas '*' || zstyle ':url-quote-magic:*' url-metas '*?[]^(|)~#{}=' @@ -84,7 +84,7 @@ zstyle -m ':urlglobber' url-other-schema '*' || # Define the "urlglobber" helper function and shorthand "globurl" alias function urlglobber { - local -a args globbed localschema otherschema + local -a args globbed localschema otherschema reply local arg command="$1" shift zstyle -s :urlglobber url-local-schema localschema '|' @@ -109,6 +109,7 @@ alias globurl='noglob urlglobber ' function url-quote-magic { setopt localoptions noksharrays extendedglob local qkey="${(q)KEYS}" + local -a reply if [[ "$KEYS" != "$qkey" ]] then local lbuf="$LBUFFER$qkey" |