diff options
Diffstat (limited to 'Completion/Core')
-rw-r--r-- | Completion/Core/_alternative | 10 | ||||
-rw-r--r-- | Completion/Core/_files | 126 | ||||
-rw-r--r-- | Completion/Core/_main_complete | 5 | ||||
-rw-r--r-- | Completion/Core/_multi_parts | 2 | ||||
-rw-r--r-- | Completion/Core/_options | 5 | ||||
-rw-r--r-- | Completion/Core/_parameters | 8 | ||||
-rw-r--r-- | Completion/Core/_path_files | 18 | ||||
-rw-r--r-- | Completion/Core/_requested | 25 | ||||
-rw-r--r-- | Completion/Core/_sep_parts | 2 | ||||
-rw-r--r-- | Completion/Core/_set_options | 5 | ||||
-rw-r--r-- | Completion/Core/_setup | 40 | ||||
-rw-r--r-- | Completion/Core/_tags | 28 | ||||
-rw-r--r-- | Completion/Core/_unset_options | 5 | ||||
-rw-r--r-- | Completion/Core/_wanted | 25 |
14 files changed, 129 insertions, 175 deletions
diff --git a/Completion/Core/_alternative b/Completion/Core/_alternative index 73292cb52..482e9db51 100644 --- a/Completion/Core/_alternative +++ b/Completion/Core/_alternative @@ -44,24 +44,26 @@ while _tags; do # Anything inside `(...)' is added directly. - compadd "$subopts[@]" "$expl[@]" - ${=action[2,-2]} + _loop "${def%%:*}" expl "$descr" \ + compadd "$subopts[@]" - ${=action[2,-2]} elif [[ "$action" = \{*\} ]]; then # A string in braces is evaluated. - eval "$action[2,-2]" + _loop "${def%%:*}" expl "$descr" eval "$action[2,-2]" elif [[ "$action" = \ * ]]; then # If the action starts with a space, we just call it. eval "action=( $action )" - "$action[@]" + _loop "${def%%:*}" expl "$descr" "$action[@]" else # Otherwise we call it with the description-arguments built above. eval "action=( $action )" - "$action[1]" "$subopts[@]" "$expl[@]" "${(@)action[2,-1]}" + _loop "${def%%:*}" expl "$descr" \ + "$action[1]" "$subopts[@]" "${(@)action[2,-1]}" fi fi done diff --git a/Completion/Core/_files b/Completion/Core/_files index 75cabda81..d4eb2b7db 100644 --- a/Completion/Core/_files +++ b/Completion/Core/_files @@ -1,105 +1,61 @@ #autoload -local opts opt type=file glob group gopts dopts aopts tmp _file_pat_checked=yes -local hasign ign +local opts tmp glob pats tags expl tag ret=1 i pat descr minus +local _comp_default_tags zparseopts -a opts \ - '/=tmp' 'f=tmp' 'g+:-=tmp' q n 1 2 P: S: r: R: W: X: M+: F: \ - 'J:=group' 'V:=group' + '/=tmp' 'f=tmp' 'g+:-=tmp' q n 1 2 P: S: r: R: W: X+: M+: F: J+: V+: type="${(@j::M)${(@)tmp#-}#?}" -[[ -n "$type" ]] || type=f -if (( $tmp[(I)-g*] )); then - gopts=( -g ${(j: :)${(M)tmp:#-g*}#-g} ) -else - gopts=() -fi -(( $opts[(I)-F] )) && hasign=yes - -[[ "$group[2]" = files ]] && opts=("$opts[@]" "$group[@]") group=() - -ign=() - -zstyle -s ":completion:${curcontext}:all-files" file-patterns tmp && - [[ -n "$tmp" ]] && - aopts=(-g "$tmp") +(( $tmp[(I)-g*] )) && glob="${(j: :)${(M)tmp:#-g*}#-g}" -if zstyle -s ":completion:${curcontext}:directories" file-patterns tmp && - [[ -n "$tmp" ]]; then - dopts=(-g "$tmp") - if [[ "$type" = (*/*g*|*g*/*) ]]; then - type=g - elif [[ "$type" != *[/g]* ]]; then - type="${type}/" - fi +if zstyle -a ":completion:${curcontext}:" file-patterns pats; then + [[ "$type" = */* ]] && glob="$glob *(-/)" + pats=( \ ${(M)^${pats/#:/ ${glob:-\*}:}:#*[^\\]:*} ) else - dopts=(-/) -fi -if zstyle -s ":completion:${curcontext}:globbed-files" file-patterns tmp && - [[ -n "$tmp" ]]; then - gopts=(-g "$tmp") - if [[ "$type" != (*/*g*|*g*/*) ]]; then - if [[ "$type" = *[g/]* ]]; then - type=g + if [[ "$type" = *g* ]]; then + if [[ "$type" = */* ]]; then + pats=( " ${glob//:/\\:} *(-/):globbed-files" '*:all-files' ) else - type=ga + pats=( " ${glob//:/\\:}:globbed-files" + '*(-/):directories' '*:all-files' ) fi + elif [[ "$type" = */* ]]; then + pats=( '*(-/):directories' '*:all-files' ) + else + pats=( '*:all-files' ) fi fi -case "$type" in -*/*g*|*g*/*) _tags globbed-files all-files ;; -*a*g*|*g*a*) _tags globbed-files all-files ;; -*g*) _tags globbed-files directories all-files ;; -*/*) _tags directories all-files ;; -*) _tags all-files ;; -esac +tags=( "${(@)${(@)pats#*[^\\]:}%%:*}" ) +_comp_default_tags=( "$tags[@]" ) + +_tags "$tags[@]" while _tags; do - if _requested all-files; then - if (( $#group )); then - group[2]=all-files - _setup all-files - [[ -z "$hasign" ]] && - zstyle -a ":completion:${curcontext}:all-files" ignored-patterns _comp_ignore && - ign=(-F _comp_ignore) - fi - _path_files "$opts[@]" "$ign[@]" "$aopts[@]" - return - elif _requested directories; then - if _requested globbed-files; then - if (( $#group )); then - group[2]=globbed-files - _setup globbed-files - [[ -z "$hasign" ]] && - zstyle -a ":completion:${curcontext}:all-files" ignored-patterns _comp_ignore && - ign=(-F _comp_ignore) - fi - _path_files "$opts[@]" "$ign[@]" "$dopts[@]" "$gopts[@]" && return 0 - else - if (( $#group )); then - group[2]=directories - _setup directories - [[ -z "$hasign" ]] && - zstyle -a ":completion:${curcontext}:all-files" ignored-patterns _comp_ignore && - ign=(-F _comp_ignore) + + for tag in "$tags[@]"; do + + if _requested "$tag"; then + + i="$pats[(I)*[^\\\\]:${tag}(|:*)]" + pat="${${pats[i]%%:${tag}*}//\\\\:/:}" + + if [[ i -gt 0 && "$pat" != \ # ]]; then + if [[ "$pats[i]" = *:${tag}:* ]]; then + descr="${pats[i]#*:${tag}:}" + minus=() + else + descr=file + minus=(-) + fi + _loop "$tag" expl "$descr" \ + _path_files -g "$pat" "$opts[@]" "$minus[@]" && ret=0 fi - _path_files "$opts[@]" "$ign[@]" "$dopts[@]" && return 0 fi - elif _requested globbed-files; then - if (( $#group )); then - group[2]=globbed-files - _setup globbed-files - [[ -z "$hasign" ]] && - zstyle -a ":completion:${curcontext}:all-files" ignored-patterns _comp_ignore && - ign=(-F _comp_ignore) - fi - if [[ "$type" = (*/*g*|*g*/*) ]]; then - _path_files "$opts[@]" "$ign[@]" "$dopts[@]" "$gopts[@]" && return 0 - else - _path_files "$opts[@]" "$ign[@]" "$gopts[@]" && return 0 - fi - fi + done + + (( ret )) || return 0 done return 1 diff --git a/Completion/Core/_main_complete b/Completion/Core/_main_complete index 63d785686..fedea9b51 100644 --- a/Completion/Core/_main_complete +++ b/Completion/Core/_main_complete @@ -20,7 +20,7 @@ setopt localoptions nullglob rcexpandparam extendedglob unsetopt markdirs globsubst shwordsplit nounset ksharrays local ctxt post ret=1 tmp _compskip format _comp_ignore \ - _completers _completer _completer_num \ + _completers _completer _completer_num curtag \ _matchers _matcher _matcher_num _comp_tags \ context state line opt_args val_args curcontext="$curcontext" \ _last_nmatches=-1 _last_menu_style _def_menu_style _menu_style sel \ @@ -31,6 +31,9 @@ local ctxt post ret=1 tmp _compskip format _comp_ignore \ typeset -U _lastdescr +_comp_opts=() +_comp_tries=() + [[ -z "$curcontext" ]] && curcontext=::: # Special completion contexts after `~' and `='. diff --git a/Completion/Core/_multi_parts b/Completion/Core/_multi_parts index 9e5906ac2..1c02e7e39 100644 --- a/Completion/Core/_multi_parts +++ b/Completion/Core/_multi_parts @@ -14,7 +14,7 @@ typeset -U tmp2 # Get the options. zparseopts -D -a sopts \ - 'J:=group' 'V:=group' 'X:=expl' 'P:=opts' 'F:=opts' \ + 'J+:=group' 'V+:=group' 'X+:=expl' 'P:=opts' 'F:=opts' \ S: r: R: q 1 2 n f 'M+:=match' 'i=imm' sopts=( "$sopts[@]" "$opts[@]" ) diff --git a/Completion/Core/_options b/Completion/Core/_options index 8664e239e..70e106247 100644 --- a/Completion/Core/_options +++ b/Completion/Core/_options @@ -4,6 +4,5 @@ local expl -_wanted zsh-options expl 'zsh option' && - compadd "$expl[@]" "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' - \ - "${(@k)options}" +_wanted zsh-options expl 'zsh option' \ + compadd "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' - "${(@k)options}" diff --git a/Completion/Core/_parameters b/Completion/Core/_parameters index c7875abcf..1e430dfc1 100644 --- a/Completion/Core/_parameters +++ b/Completion/Core/_parameters @@ -3,10 +3,6 @@ # This should be used to complete parameter names if you need some of the # extra options of compadd. It completes only non-local parameters. -local pars expl +local expl -_wanted parameters expl parameter || return 1 - -pars=( ${(k)parameters[(R)^*local*]} ) - -compadd "$expl[@]" "$@" - $pars +_wanted parameters expl parameter compadd "$@" - ${(k)parameters[(R)^*local*]} diff --git a/Completion/Core/_path_files b/Completion/Core/_path_files index ad956bb72..21ca05529 100644 --- a/Completion/Core/_path_files +++ b/Completion/Core/_path_files @@ -20,7 +20,7 @@ exppaths=() zparseopts -a mopts \ 'P:=pfxsfx' 'S:=pfxsfx' 'q=pfxsfx' 'r:=pfxsfx' 'R:=pfxsfx' \ 'W:=prepaths' 'F:=ignore' 'M+:=matcher' \ - J: V: X: 1: 2: n: 'f=tmp1' '/=tmp1' 'g+:-=tmp1' + J+: V+: X+: 1: 2: n: 'f=tmp1' '/=tmp1' 'g+:-=tmp1' sopt="-${(@j::M)${(@)tmp1#-}#?}" (( $tmp1[(I)-[/g]*] )) && haspats=yes @@ -54,20 +54,6 @@ if (( $#ignore )); then fi fi -if [[ -z "$_file_pat_checked" ]] && - zstyle -s ":completion:${curcontext}:files" file-patterns tmp1 && - [[ -n "$tmp1" ]]; then - if [[ "$tmp1" = '*(-/)' ]]; then - gopt='' - sopt=-/ - else - gopt=yes - sopt=- - fi - pats=( $=tmp1 ) - haspats=yes -fi - # If we were given no file selection option, we behave as if we were given # a `-f'. @@ -155,7 +141,7 @@ eorig="$orig" # If given no `-F' option, we may want to use $fignore, turned into patterns. -[[ $#ignore -eq 0 && -z $gopt && -n $FIGNORE ]] && +[[ $#ignore -eq 0 && ( -z $gopt || "$pats" = \ #\*\ # ) && -n $FIGNORE ]] && ignore=( "?*${^fignore[@]}" ) if (( $#ignore )); then diff --git a/Completion/Core/_requested b/Completion/Core/_requested index b5efb5a9e..41122819a 100644 --- a/Completion/Core/_requested +++ b/Completion/Core/_requested @@ -1,15 +1,20 @@ #autoload -local tag +local gopt=-J -if [[ "$1" = -[VJ]* ]]; then - tag="$2" -else - tag="$1" +if [[ "$1" = -([12]|)[VJ] ]]; then + gopt="$1" + shift fi -comptags -R "$tag" && _comp_tags="$_comp_tags $tag" && - if [[ $# -gt 1 ]]; then - _description "$@" - return 0 - fi +if comptags -R "$1"; then + _comp_tags="$_comp_tags $1" + if [[ $# -gt 3 ]]; then + _loop "$gopt" "$@" + elif [[ $# -gt 1 ]]; then + _description "$gopt" "$@" + fi + return 0 +else + return 1 +fi diff --git a/Completion/Core/_sep_parts b/Completion/Core/_sep_parts index 11fb20ab6..2ea0e6c68 100644 --- a/Completion/Core/_sep_parts +++ b/Completion/Core/_sep_parts @@ -23,7 +23,7 @@ local matchflags opt group expl nm=$compstate[nmatches] opre osuf opts match # Get the options. zparseopts -D -a opts \ - 'J:=group' 'V:=group' P: F: S: r: R: q 1 2 n 'X:=expl' 'M+:=match' + 'J+:=group' 'V+:=group' P: F: S: r: R: q 1 2 n 'X+:=expl' 'M+:=match' if (( $#match )); then match="${match[2]}" diff --git a/Completion/Core/_set_options b/Completion/Core/_set_options index ae4d3784e..ea851d64a 100644 --- a/Completion/Core/_set_options +++ b/Completion/Core/_set_options @@ -6,6 +6,5 @@ local expl -_wanted zsh-options expl 'set zsh option' && - compadd "$expl[@]" "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' - \ - $=_set_options +_wanted zsh-options expl 'set zsh option' \ + compadd "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' - $=_set_options diff --git a/Completion/Core/_setup b/Completion/Core/_setup index 5d63b97ce..0b9e5d0a9 100644 --- a/Completion/Core/_setup +++ b/Completion/Core/_setup @@ -18,42 +18,34 @@ if zstyle -a ":completion:${curcontext}:$1" list-colors val; then fi -if zstyle -s ":completion:${curcontext}:$1" list-packed val; then - if [[ "$val" = (yes|true|1|on) ]]; then - compstate[list]="${compstate[list]} packed" - else - compstate[list]="${compstate[list]:gs/packed//}" - fi +if zstyle -t ":completion:${curcontext}:$1" list-packed; then + compstate[list]="${compstate[list]} packed" +elif [[ $? -eq 1 ]]; then + compstate[list]="${compstate[list]:gs/packed//}" else compstate[list]="$_saved_list" fi -if zstyle -s ":completion:${curcontext}:$1" list-rows-first val; then - if [[ "$val" = (yes|true|1|on) ]]; then - compstate[list]="${compstate[list]} rows" - else - compstate[list]="${compstate[list]:gs/rows//}" - fi +if zstyle -t ":completion:${curcontext}:$1" list-rows-first; then + compstate[list]="${compstate[list]} rows" +elif [[ $? -eq 1 ]]; then + compstate[list]="${compstate[list]:gs/rows//}" else compstate[list]="$_saved_list" fi -if zstyle -s ":completion:${curcontext}:$1" last-prompt val; then - if [[ "$val" = (yes|true|1|on) ]]; then - compstate[last_prompt]=yes - else - compstate[last_prompt]='' - fi +if zstyle -t ":completion:${curcontext}:$1" last-prompt; then + compstate[last_prompt]=yes +elif [[ $? -eq 1 ]]; then + compstate[last_prompt]='' else compstate[last_prompt]="$_saved_lastprompt" fi -if zstyle -s ":completion:${curcontext}:$1" accept-exact val; then - if [[ "$val" = (yes|true|1|on) ]]; then - compstate[exact]=accept - else - compstate[exact]='' - fi +if zstyle -t ":completion:${curcontext}:$1" accept-exact; then + compstate[exact]=accept +elif [[ $? -eq 1 ]]; then + compstate[exact]='' else compstate[exact]="$_saved_exact" fi diff --git a/Completion/Core/_tags b/Completion/Core/_tags index 6e3966074..b74e70264 100644 --- a/Completion/Core/_tags +++ b/Completion/Core/_tags @@ -50,21 +50,31 @@ if (( $# )); then fi ;; \!*) comptry "${(@)argv:#(${(j:|:)~${=tag[2,-1]}})}";; - ?*) comptry ${=tag};; + ?*) comptry ${${(ps: :)${tag//\\\\ /$'\0'}}//$'\0'/ };; esac done - [[ -z "$nodef" ]] && comptry "$@" + if [[ -z "$nodef" ]]; then + if (( $+_comp_default_tags )); then + for tag in "$_comp_default_tags[@]"; do + comptry "$tag" + done + else + comptry "$@" + fi + fi else - # The first ones give the default behaviour. - - comptry arguments values - comptry options - comptry globbed-files - comptry directories - comptry all-files + # Use default tags... + if (( $+_comp_default_tags )); then + for tag in "$_comp_default_tags[@]"; do + comptry "$tag" + done + else + comptry arguments values + comptry options + fi comptry "$@" fi diff --git a/Completion/Core/_unset_options b/Completion/Core/_unset_options index 8c8ed780d..d06866517 100644 --- a/Completion/Core/_unset_options +++ b/Completion/Core/_unset_options @@ -6,6 +6,5 @@ local expl -_wanted zsh-options expl 'unset zsh option' && - compadd "$expl[@]" "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' - \ - $=_unset_options +_wanted zsh-options expl 'unset zsh option' \ + compadd "$@" -M 'L:|[nN][oO]= M:_= M:{A-Z}={a-z}' - $=_unset_options diff --git a/Completion/Core/_wanted b/Completion/Core/_wanted index 400daa701..1d6dcdb59 100644 --- a/Completion/Core/_wanted +++ b/Completion/Core/_wanted @@ -1,6 +1,6 @@ #autoload -local targs tag +local targs gopt=-J if [[ "$1" = -C?* ]]; then targs=( -C "${1[3,-1]}" ) @@ -12,15 +12,22 @@ else targs=() fi -if [[ "$1" = -[VJ]* ]]; then - tag="$2" -else - tag="$1" +if [[ "$1" = -([12]|)[VJ] ]]; then + gopt="$1" + shift fi -if [[ $# -gt 1 ]]; then - _tags "$targs[@]" "$tag" && _comp_tags="$_comp_tags $tag" && - _description "$@" +if [[ $# -gt 3 ]]; then + if _tags "$targs[@]" "$1"; then + _comp_tags="$_comp_tags $1" + + _loop -t "$gopt" "$@" + else + return 1 + fi +elif [[ $# -gt 1 ]]; then + _tags "$targs[@]" "$1" && _comp_tags="$_comp_tags $1" && + _description "$gopt" "$@" else - _tags "$targs[@]" "$tag" && _comp_tags="$_comp_tags $tag" + _tags "$targs[@]" "$1" && _comp_tags="$_comp_tags $1" fi |