diff options
Diffstat (limited to 'Completion/Base/_arguments')
-rw-r--r-- | Completion/Base/_arguments | 70 |
1 files changed, 25 insertions, 45 deletions
diff --git a/Completion/Base/_arguments b/Completion/Base/_arguments index f819f69c9..1fcf34a10 100644 --- a/Completion/Base/_arguments +++ b/Completion/Base/_arguments @@ -4,7 +4,7 @@ # descriptions given as arguments to this function. local long cmd="$words[1]" descr mesg subopts opt usecc autod -local oldcontext="$curcontext" hasopts multi ismulti +local oldcontext="$curcontext" hasopts long=$argv[(I)--] if (( long )); then @@ -23,7 +23,7 @@ if (( long )); then name="${name//[^a-zA-Z0-9_]/_}" if (( ! ${(P)+name} )); then - local iopts sopts pattern tmpo cur cache + local iopts sopts pattern tmpo dir cur cache typeset -U lopts cache=() @@ -98,6 +98,12 @@ if (( long )); then pattern="${${${(M)1#*[^\\]:}[1,-2]}//\\\\:/:}" descr="${1#${pattern}}" + if [[ "$pattern" = *\(-\) ]]; then + pattern="$pattern[1,-4]" + dir=- + else + dir= + fi shift # We get all options matching the pattern and take them from the @@ -111,7 +117,7 @@ if (( long )); then opt='' - # If there are option strings with a `[=', we take these get an + # If there are option strings with a `[=', we take these to get an # optional argument. tmpo=("${(@M)tmp:#*\[\=*}") @@ -120,9 +126,9 @@ if (( long )); then tmpo=("${(@)${(@)tmpo%%\=*}//[^a-z0-9-]}") if [[ "$descr" = ::* ]]; then - cache=( "$cache[@]" "${(@)^tmpo}=${descr}" ) + cache=( "$cache[@]" "${(@)^tmpo}=${dir}${descr}" ) else - cache=( "$cache[@]" "${(@)^tmpo}=:${descr}" ) + cache=( "$cache[@]" "${(@)^tmpo}=${dir}:${descr}" ) fi fi @@ -133,10 +139,10 @@ if (( long )); then tmp=("${(@)tmp:#*\=*}") tmpo=("${(@)${(@)tmpo%%\=*}//[^a-z0-9-]}") - cache=( "$cache[@]" "${(@)^tmpo}=${descr}" ) + cache=( "$cache[@]" "${(@)^tmpo}=${dir}${descr}" ) fi - # Everything else is just added as a option without arguments. + # Everything else is just added as an option without arguments. if (( $#tmp )); then tmp=("${(@)tmp//[^a-zA-Z0-9-]}") @@ -148,27 +154,22 @@ if (( long )); then set -- "$tmpargv[@]" "${(@P)name}" fi -multi=(-i) subopts=() while [[ "$1" = -(O*|C|m*) ]]; do case "$1" in -C) usecc=yes; shift ;; -O) subopts=( "${(@P)2}" ); shift 2 ;; -O*) subopts=( "${(@P)1[3,-1]}" ); shift ;; - -m) ismulti=yes multi=(-I "$2" "$3"); shift 3 ;; - -m*) ismulti=yes multi=(-I "${1[3,-1]}" "$2"); shift 2 ;; esac done zstyle -s ":completion:${curcontext}:options" auto-description autod -if (( $# )) && comparguments "$multi[@]" "$autod" "$@"; then +if (( $# )) && comparguments -i "$autod" "$@"; then local action noargs aret expl local tried local next direct odirect equal single matcher matched ws tmp1 tmp2 tmp3 local opts subc tc prefix suffix descrs actions subcs - local origpre="$PREFIX" origipre="$IPREFIX" - - [[ -z "$ismulti" ]] && local nm="$compstate[nmatches]" + local origpre="$PREFIX" origipre="$IPREFIX" nm="$compstate[nmatches]" if comparguments -D descrs actions subcs; then if comparguments -O next direct odirect equal; then @@ -180,7 +181,6 @@ if (( $# )) && comparguments "$multi[@]" "$autod" "$@"; then else if comparguments -a; then noargs='no more arguments' - had_args=yes else noargs='no arguments' fi @@ -299,8 +299,7 @@ if (( $# )) && comparguments "$multi[@]" "$autod" "$@"; then done if [[ -z "$matched$hasopts" ]] && _requested options && - { [[ -n "$ismulti" ]] || - ! zstyle -T ":completion:${curcontext}:options" prefix-needed || + { ! zstyle -T ":completion:${curcontext}:options" prefix-needed || [[ "$origpre" = [-+]* || -z "$aret$mesg$tried" ]] } ; then local prevpre="$PREFIX" previpre="$IPREFIX" @@ -326,37 +325,22 @@ if (( $# )) && comparguments "$multi[@]" "$autod" "$@"; then tmp1=( "${(M@)tmp1:#[-+]?(|:*)}" ) tmp2=( "${PREFIX}${(@M)^${(@)${(@)tmp1%%:*}#[-+]}:#?}" ) - if [[ -n "$ismulti" ]]; then - _ms_opt=yes - _ms_soptmid=( "$_ms_soptmid[@]" "$tmp1[@]" ) - _ms_soptmidadd=( "$_ms_soptmidadd[@]" "$tmp2[@]" ) - _ms_soptend=( "$_ms_soptend[@]" "$tmp3[@]" ) - else - _describe -o option \ - tmp1 tmp2 -Q -S '' -- \ - tmp3 -Q - fi + _describe -o option \ + tmp1 tmp2 -Q -S '' -- \ + tmp3 -Q fi single=yes else next=( "$next[@]" "$odirect[@]" ) - if [[ -n "$ismulti" ]]; then - _ms_opt=yes - _ms_match="$_ms_match $matcher" - _ms_optnext=( "$_ms_optnext[@]" "$next[@]" ) - _ms_optdirect=( "$_ms_optdirect[@]" "$direct[@]" ) - _ms_optequal=( "$_ms_optequal[@]" "$equal[@]" ) - else - _describe -o option \ - next -Q -M "$matcher" -- \ - direct -QS '' -M "$matcher" -- \ - equal -QqS= -M "$matcher" - fi + _describe -o option \ + next -Q -M "$matcher" -- \ + direct -QS '' -M "$matcher" -- \ + equal -QqS= -M "$matcher" fi PREFIX="$prevpre" IPREFIX="$previpre" fi - [[ -n "$tried" ]] && break + [[ -n "$tried" && "$PREFIX" != [-+]* ]] && break done if [[ -n "$opts" && -z "$aret$matched$mesg" && nm -eq compstate[nmatches] ]]; then @@ -391,11 +375,7 @@ if (( $# )) && comparguments "$multi[@]" "$autod" "$@"; then [[ -n "$aret" ]] && return 300 - if [[ -n "$noargs" ]]; then - [[ -z "$ismulti" && nm -eq "$compstate[nmatches]" ]] && _message "$noargs" - else - has_args=yes - fi + [[ -n "$noargs" && nm -eq "$compstate[nmatches]" ]] && _message "$noargs" # Set the return value. |