From 8bc41ba869dbbd3c6bc2c8f2338c740311074f23 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Wed, 15 Dec 1999 17:35:20 +0000 Subject: manual/9058 --- Completion/Base/_arguments | 3 ++- Completion/Base/_combination | 4 +-- Completion/Base/_command_names | 2 +- Completion/Base/_jobs | 29 +++++++++++++++------ Completion/Base/_tilde | 4 +-- Completion/Builtins/_cd | 2 +- Completion/Builtins/_kill | 4 +-- Completion/Builtins/_stat | 8 +++--- Completion/Builtins/_wait | 2 +- Completion/Core/_path_files | 11 +++++--- Completion/Core/_sort_tags | 59 +++++++++++++++++------------------------- Completion/Core/_tags | 21 ++++++++++++--- Completion/Core/compinit | 2 ++ 13 files changed, 88 insertions(+), 63 deletions(-) (limited to 'Completion') diff --git a/Completion/Base/_arguments b/Completion/Base/_arguments index 16293a098..5a6ee1930 100644 --- a/Completion/Base/_arguments +++ b/Completion/Base/_arguments @@ -259,7 +259,8 @@ if (( $# )) && comparguments -i "$autod" "$@"; then if [[ -z "$matched" ]] && _requested options && { ! zstyle -t ":completion${curcontext}:options" prefix-needed || - [[ "$origpre" = [-+]* ]] } ; then + [[ "$origpre" = [-+]* || + ( -z "$aret$mesg" && nm -eq compstate[nmatches] ) ]] } ; then local prevpre="$PREFIX" previpre="$IPREFIX" PREFIX="$origpre" diff --git a/Completion/Base/_combination b/Completion/Base/_combination index ffda5cae9..e7548f19f 100644 --- a/Completion/Base/_combination +++ b/Completion/Base/_combination @@ -21,7 +21,7 @@ # `_telnet' completes hosts as: # # _combination my-accounts hosts-ports-users \ -# ${options[-l]:+users=${options[-l]:q}} \ +# ${opt_args[-l]:+users=${opt_args[-l]:q}} \ # hosts "$expl[@]" # # This completes `host1', `host2', `mail-server', `news-server' and @@ -31,7 +31,7 @@ # `_telnet' completes ports as: # # _combination my-accounts hosts-ports-users \ -# ${options[-l]:+users=${options[-l]:q}} \ +# ${opt_args[-l]:+users=${opt_args[-l]:q}} \ # hosts="${line[2]:q}" \ # ports "$expl[@]" # diff --git a/Completion/Base/_command_names b/Completion/Base/_command_names index 63c8601e9..12caf926f 100644 --- a/Completion/Base/_command_names +++ b/Completion/Base/_command_names @@ -17,11 +17,11 @@ else [[ "$1" = - ]] && shift defs=( "$defs[@]" - 'jobs:: _jobs' 'builtins:builtin command:compadd - ${(@k)builtins}' 'functions:shell function:compadd - ${(@k)functions}' 'aliases:alias:compadd - ${(@k)aliases}' 'reserved-words:reserved word:compadd - ${(@k)reswords}' + 'jobs:: _jobs -t' ) fi diff --git a/Completion/Base/_jobs b/Completion/Base/_jobs index ff9fa5a62..48d74c307 100644 --- a/Completion/Base/_jobs +++ b/Completion/Base/_jobs @@ -1,11 +1,14 @@ #autoload -local expl disp jobs job jids pfx='%' desc +local expl disp jobs job jids pfx='%' desc how _tags jobs || return 1 -zstyle -t ":completion${curcontext}:jobs" prefix-needed && - [[ "$PREFIX" != %* ]] && return 1 +if [[ "$1" = -t ]]; then + zstyle -t ":completion${curcontext}:jobs" prefix-needed && + [[ "$PREFIX" != %* || compstate[nmatches] -eq 0 ]] && return 1 + shift +fi zstyle -t ":completion${curcontext}:jobs" prefix-hidden && pfx='' zstyle -t ":completion${curcontext}:jobs" verbose && desc=yes @@ -31,8 +34,12 @@ if [[ -n "$desc" ]]; then done fi -if zstyle -t ":completion${curcontext}:jobs" strings; then - local texts i text str tmp +zstyle -s ":completion${curcontext}:jobs" numbers how + +if [[ "$how" = (yes|true|on|1) ]]; then + jobs=( "$jids[@]" ) +else + local texts i text str tmp num max=0 # Find shortest unambiguous strings. @@ -47,6 +54,7 @@ if zstyle -t ":completion${curcontext}:jobs" strings; then text="" fi tmp=( "${(@M)texts:#${str}*}" ) + num=1 while [[ -n "$text" && $#tmp -ge 2 ]]; do str="${str} ${text%% *}" if [[ "$text" = *\ * ]]; then @@ -55,14 +63,19 @@ if zstyle -t ":completion${curcontext}:jobs" strings; then text="" fi tmp=( "${(@M)texts:#${str}*}" ) + (( num++ )) done + [[ num -gt max ]] && max="$num" + jobs=( "$jobs[@]" "$str" ) done - [[ -n "$pfx" && -n "$desc" ]] && disp=( "${(@)disp#%}" ) -else - jobs=( "$jids[@]" ) + if [[ "$how" = [0-9]## && max -gt how ]]; then + jobs=( "$jids[@]" ) + else + [[ -z "$pfx" && -n "$desc" ]] && disp=( "${(@)disp#%}" ) + fi fi if [[ -n "$desc" ]]; then diff --git a/Completion/Base/_tilde b/Completion/Base/_tilde index bba928f50..128fd7ffa 100644 --- a/Completion/Base/_tilde +++ b/Completion/Base/_tilde @@ -4,7 +4,7 @@ # for you or if there are too many of them, you may want to use # `compadd -qS/ - "$friends[@]"' or something like that. -local expl suf dirs list lines revlines i ret disp +local expl suf dirs list lines revlines i ret disp nm="$compstate[nmatches]" if [[ "$SUFFIX" = */* ]]; then ISUFFIX="/${SUFFIX#*/}$ISUFFIX" @@ -23,7 +23,7 @@ while _tags; do if _requested -V directory-stack expl 'directory stack' && { ! zstyle -t ":completion${curcontext}:directory-stack" prefix-needed || - [[ "$PREFIX" = [-+]* ]] }; then + [[ "$PREFIX" = [-+]* || nm -eq compstate[nmatches] ]] }; then if zstyle -t ":completion${curcontext}:directory-stack" verbose; then integer i diff --git a/Completion/Builtins/_cd b/Completion/Builtins/_cd index f8b01bc66..8e72bd7ad 100644 --- a/Completion/Builtins/_cd +++ b/Completion/Builtins/_cd @@ -39,7 +39,7 @@ elif _popd || [[ $PREFIX != (\~|/|./|../)* && $#cdpath -ne 0 ]]; then else _alternative \ 'local-directories:local directories:_path_files -/' \ - 'path-directories: directories in cdpath:_path_files -W \(${cdpath:#.}\) -/' + "path-directories: directories in cdpath:_path_files -W \\(${${(@)cdpath:#.}}\\) -/" fi else _path_files -/ diff --git a/Completion/Builtins/_kill b/Completion/Builtins/_kill index 44442ef8f..5e3caed6a 100644 --- a/Completion/Builtins/_kill +++ b/Completion/Builtins/_kill @@ -2,5 +2,5 @@ _alternative \ 'signals:: _signals -p' \ - 'jobs:: _jobs' \ - 'processes:: _pids' + 'processes:: _pids' \ + 'jobs:: _jobs -t' diff --git a/Completion/Builtins/_stat b/Completion/Builtins/_stat index 232cf672b..3b192c297 100644 --- a/Completion/Builtins/_stat +++ b/Completion/Builtins/_stat @@ -1,19 +1,19 @@ #compdef stat -local expl +local expl ret=1 if [[ "$words[CURRENT-1]" = -[AH] ]]; then _arrays else - _tags options files || return 1 + _tags files options || return 1 while _tags; do + _requested files && _files && ret=0 _requested options expl 'inode element' && { ! zstyle -t ":completion${curcontext}:options" prefix-needed || - [[ "$PREFIX[1]" = + ]] } && + [[ "$PREFIX[1]" = + || ret -eq 1 ]] } && compadd "$expl[@]" - +device +inode +mode +nlink +uid +gid +rdev \ +size +atime +mtime +ctime +blksize +block +link fi - _requested files && _files done fi diff --git a/Completion/Builtins/_wait b/Completion/Builtins/_wait index 28fdb7985..c007cab90 100644 --- a/Completion/Builtins/_wait +++ b/Completion/Builtins/_wait @@ -1,3 +1,3 @@ #compdef wait -_alternative 'jobs:: _jobs' 'processes:: _pids' +_alternative 'processes:: _pids' 'jobs:: _jobs -t' diff --git a/Completion/Core/_path_files b/Completion/Core/_path_files index bbed17a1f..dd9934506 100644 --- a/Completion/Core/_path_files +++ b/Completion/Core/_path_files @@ -4,7 +4,7 @@ # to complete to `/usr/local/bin'. local linepath realpath donepath prepath testpath exppath -local tmp1 tmp2 tmp3 tmp4 i orig pre suf tpre tsuf opre osuf cpre +local tmp1 tmp2 tmp3 tmp4 i orig eorig pre suf tpre tsuf opre osuf cpre local pats haspats=no ignore group expl addpfx addsfx remsfx local nm=$compstate[nmatches] menu match matcher mopts atmp @@ -108,6 +108,7 @@ suf="$SUFFIX" opre="$PREFIX" osuf="$SUFFIX" orig="${PREFIX}${SUFFIX}" +eorig="$orig" [[ $compstate[insert] = (*menu|[0-9]*) || -n "$_comp_correct" || ( $#compstate[pattern_match] -ne 0 && @@ -265,7 +266,11 @@ for prepath in "$prepaths[@]"; do if [[ "$tmp2[1]" = */* ]]; then tmp2=( "${(@)tmp2:h}" ) compquote tmp2 - exppaths=( "$exppaths[@]" ${^tmp2}/${tpre}${tsuf} ) + if [[ "$tmp2" = */ ]]; then + exppaths=( "$exppaths[@]" ${^tmp2}${tpre}${tsuf} ) + else + exppaths=( "$exppaths[@]" ${^tmp2}/${tpre}${tsuf} ) + fi else exppaths=( "$exppaths[@]" ${tpre}${tsuf} ) fi @@ -453,7 +458,7 @@ done # expanded paths that are different from the string on the line, we add # them as possible matches. -exppaths=( "${(@)exppaths:#$orig}" ) +exppaths=( "${(@)exppaths:#$eorig}" ) if zstyle -t ":completion${curcontext}:paths" expand prefix && [[ $#exppaths -gt 0 && nm -eq compstate[nmatches] ]]; then diff --git a/Completion/Core/_sort_tags b/Completion/Core/_sort_tags index 20897823a..6f07eec1c 100644 --- a/Completion/Core/_sort_tags +++ b/Completion/Core/_sort_tags @@ -1,39 +1,28 @@ #autoload -local stags tag +comptry arguments values +comptry options -if zstyle -a ":completion${curcontext}" sort-tags stags; then +case "$curcontext" in +# Some silly examples commented out: +# +# *::*p[bgpn]m:*) # change the order for file-completion +# comptry globbed-files directories +# comptry all-files +# ;; +# *::dvips::-o*) # automatic context set by _arguments +# comptry all-files +# return +# ;; +# *::kill:*) +# comptry processes +# return # this return ensures that we use only processes +# ;; +*) + comptry globbed-files + comptry directories + comptry all-files + ;; +esac - for tag in $stags; do - [[ $tag != '' ]] && comptry ${=tag} - done - -else - - comptry arguments values - comptry options - - case "$curcontext" in - # Some silly examples commented out: - # - # *::*p[bgpn]m:*) # change the order for file-completion - # comptry globbed-files directories - # comptry all-files - # ;; - # *::dvips::-o*) # automatic context set by _arguments - # comptry all-files - # return - # ;; - # *::kill:*) - # comptry processes - # return # this return ensures that we use only processes - # ;; - *) - comptry globbed-files - comptry directories - comptry all-files - ;; - esac - - comptry "$@" -fi +comptry "$@" diff --git a/Completion/Core/_tags b/Completion/Core/_tags index fcef91061..e913095c4 100644 --- a/Completion/Core/_tags +++ b/Completion/Core/_tags @@ -4,7 +4,7 @@ if (( $# )); then # We have arguments: the tags supported in this context. - local curcontext="$curcontext" order + local curcontext="$curcontext" order tag nodef if [[ "$1" = -C?* ]]; then curcontext="${curcontext}:${1[3,-1]}" @@ -38,9 +38,24 @@ if (( $# )); then _offered_tags=( "$_offered_tags[@]" "$@" ) _last_tags=() - # Call the function that sorts the tags into sets. + # Sort the tags. - "${_sort_tags:-_sort_tags}" "$@" + if [[ -n "$_sort_tags" ]]; then + "$_sort_tags" "$@" + elif zstyle -a ":completion${curcontext}" tag-order order; then + + for tag in $order; do + case $tag in + -) nodef=yes;; + *\(\)) "${${tag%%[ ]#\(\)}##[ ]#}" "$@";; + ?*) comptry ${=tag};; + esac + done + + [[ -z "$nodef" ]] && comptry "$@" + else + comptry "$@" + fi # Return non-zero if at least one set of tags should be used. diff --git a/Completion/Core/compinit b/Completion/Core/compinit index 09fb68467..8d6d20459 100644 --- a/Completion/Core/compinit +++ b/Completion/Core/compinit @@ -479,6 +479,8 @@ zstyle ':completion:correct' max-errors '2' numeric zstyle ':completion:correct' prompt 'correct to:' zstyle ':completion:*' completer '_complete' zstyle ':completion*:default' list-colors no=0 fi=0 di=0 ln=0 pi=0 so=0 bd=0 cd=0 ex=0 +zstyle ':completion:*' tag-order 'arguments values' options \ + globbed-files directories all-files # Now we automatically make the definition files autoloaded. -- cgit 1.4.1