diff options
Diffstat (limited to 'Completion/Base')
-rw-r--r-- | Completion/Base/_arguments | 176 | ||||
-rw-r--r-- | Completion/Base/_describe | 35 | ||||
-rw-r--r-- | Completion/Base/_values | 13 |
3 files changed, 112 insertions, 112 deletions
diff --git a/Completion/Base/_arguments b/Completion/Base/_arguments index ca8f42c61..04d588c49 100644 --- a/Completion/Base/_arguments +++ b/Completion/Base/_arguments @@ -154,122 +154,127 @@ fi if comparguments -i "$compconfig[autodescribe_options]" "$@"; then local nm="$compstate[nmatches]" action noargs aret expl local local next direct odirect equal single match matched ws tmp1 tmp2 + local prios tags opts - if ! comparguments -D descr action; then + if comparguments -D descr action; then + if comparguments -O next direct odirect equal; then + opts=yes + _tags -f "$funcstack[2]" argument option + else + _tags -f "$funcstack[2]" argument + fi + else if comparguments -a; then noargs='no more arguments' else noargs='no arguments' fi - fi + comparguments -O next direct odirect equal || return 1 - while true; do + opts=yes + _tags -f "$funcstack[2]" option + fi - if [[ -z "$noargs" || -n "$matched" ]]; then - _description expl "$descr" + while _tags; do + while true; do + if [[ "$tags" = *:argument* ]]; then + _description expl "$descr" - if [[ "$action" = -\>* ]]; then - comparguments -W line opt_args - state="${${action[3,-1]##[ ]#}%%[ ]#}" - compstate[restore]='' - aret=yes - else - if [[ -z "$local" ]]; then - local line - typeset -A opt_args - local=yes - fi + if [[ "$action" = -\>* ]]; then + comparguments -W line opt_args + state="${${action[3,-1]##[ ]#}%%[ ]#}" + compstate[restore]='' + aret=yes + else + if [[ -z "$local" ]]; then + local line + typeset -A opt_args + local=yes + fi - comparguments -W line opt_args + comparguments -W line opt_args - if [[ "$action" = \ # ]]; then + if [[ "$action" = \ # ]]; then - # An empty action means that we should just display a message. + # An empty action means that we should just display a message. - [[ -n "$matched" ]] && compadd -n -Q -S '' -s "$SUFFIX" - "$PREFIX" - mesg="$descr" + [[ -n "$matched" ]] && compadd -n -Q -S '' -s "$SUFFIX" - "$PREFIX" + mesg="$descr" - elif [[ "$action" = \(\(*\)\) ]]; then + elif [[ "$action" = \(\(*\)\) ]]; then - # ((...)) contains literal strings with descriptions. + # ((...)) contains literal strings with descriptions. - eval ws\=\( "${action[3,-3]}" \) + eval ws\=\( "${action[3,-3]}" \) - _describe -c "$cmd" "$descr" ws -M "$match" + _describe -c "$cmd" -f "$funcstack[2]" "$descr" ws -M "$match" - elif [[ "$action" = \(*\) ]]; then + elif [[ "$action" = \(*\) ]]; then - # Anything inside `(...)' is added directly. + # Anything inside `(...)' is added directly. - compadd "$expl[@]" - ${=action[2,-2]} - elif [[ "$action" = \{*\} ]]; then + compadd "$expl[@]" - ${=action[2,-2]} + elif [[ "$action" = \{*\} ]]; then - # A string in braces is evaluated. + # A string in braces is evaluated. - eval "$action[2,-2]" + eval "$action[2,-2]" - elif [[ "$action" = \ * ]]; then + elif [[ "$action" = \ * ]]; then - # If the action starts with a space, we just call it. + # If the action starts with a space, we just call it. - ${(e)=~action} - else + ${(e)=~action} + else - # Otherwise we call it with the description-arguments built above. + # Otherwise we call it with the description-arguments built above. - action=( $=action ) - ${(e)action[1]} "$expl[@]" ${(e)~action[2,-1]} + action=( $=action ) + ${(e)action[1]} "$expl[@]" ${(e)~action[2,-1]} + fi fi fi - fi - - if [[ -z "$matched" ]] && - comparguments -O next direct odirect equal && - [[ ( ( nm -eq compstate[nmatches] || -n "$noargs" ) && - -z "$aret" && -z "$mesg" ) || - -z "$compconfig[option_prefix]" || - "$compconfig[option_prefix]" = *\!${cmd}* || - "$PREFIX" = [-+]* ]]; then - - comparguments -M match - - if comparguments -s single; then - - _description expl option - - if [[ "$single" = direct ]]; then - compadd "$expl[@]" -QS '' - "${PREFIX}${SUFFIX}" - elif [[ "$single" = next ]]; then - compadd "$expl[@]" -Q - "${PREFIX}${SUFFIX}" - elif [[ "$single" = equal ]]; then - compadd "$expl[@]" -QqS= - "${PREFIX}${SUFFIX}" + if [[ "$tags" = *:option* && + ( "$tags" != *\[*prefix*\]* || "$PREFIX" = [-+]* ) ]]; then + comparguments -M match + + if comparguments -s single; then + + _description expl option + + if [[ "$single" = direct ]]; then + compadd "$expl[@]" -QS '' - "${PREFIX}${SUFFIX}" + elif [[ "$single" = next ]]; then + compadd "$expl[@]" -Q - "${PREFIX}${SUFFIX}" + elif [[ "$single" = equal ]]; then + compadd "$expl[@]" -QqS= - "${PREFIX}${SUFFIX}" + else + tmp1=( "$next[@]" "$direct[@]" "$odirect[@]" "$equal[@]" ) + tmp1=( "${(M@)tmp1:#[-+]?(|:*)}" ) + tmp2=( "${PREFIX}${(@M)^${(@)${(@)tmp1%%:*}#[-+]}:#?}" ) + + _describe -o -c "$cmd" -f "$funcstack[2]" option \ + tmp1 tmp2 -Q -S '' + fi + single=yes else - tmp1=( "$next[@]" "$direct[@]" "$odirect[@]" "$equal[@]" ) - tmp1=( "${(M@)tmp1:#[-+]?(|:*)}" ) - tmp2=( "${PREFIX}${(@M)^${(@)${(@)tmp1%%:*}#[-+]}:#?}" ) - - _describe -o -c "$cmd" option tmp1 tmp2 -Q -S '' + next=( "$next[@]" "$odirect[@]" ) + _describe -o -c "$cmd" -f "$funcstack[2]" option \ + next -Q -M "$match" -- \ + direct -QS '' -M "$match" -- \ + equal -QqS= -M "$match" fi - single=yes - else - next=( "$next[@]" "$odirect[@]" ) - _describe -o -c "$cmd" option \ - next -Q -M "$match" -- \ - direct -QS '' -M "$match" -- \ - equal -QqS= -M "$match" fi - - if [[ nm -eq compstate[nmatches] && -z "$aret" && - ( ( -z "$single" && "$PREFIX" = [-+]*\=* ) || - "$PREFIX" = --* ) ]]; then + if [[ -n "$opts" && -z "$aret$matched" && nm -ne compstate[nmatches] && + "$tags" = *:argument* ]]; then local prefix suffix - prefix="${PREFIX#*\=}" - suffix="$SUFFIX" - PREFIX="${PREFIX%%\=*}" - SUFFIX='' - compadd -M "$match" -D equal - "${(@)equal%%:*}" + prefix="${PREFIX#*\=}" + suffix="$SUFFIX" + PREFIX="${PREFIX%%\=*}" + SUFFIX='' + compadd -M "$match" -D equal - "${(@)equal%%:*}" if [[ $#equal -eq 1 ]]; then PREFIX="$prefix" @@ -277,11 +282,13 @@ if comparguments -i "$compconfig[autodescribe_options]" "$@"; then IPREFIX="${IPREFIX}${equal[1]%%:*}=" matched=yes comparguments -L "$equal[1]" descr action + tags=argument continue - fi + fi fi - fi - break + break + done + [[ -n "$aret" || nm -ne compstate[nmatches] ]] && break done [[ -n "$aret" ]] && return 300 @@ -292,7 +299,6 @@ if comparguments -i "$compconfig[autodescribe_options]" "$@"; then # Set the return value. [[ nm -ne "$compstate[nmatches]" ]] - else return 1 fi diff --git a/Completion/Base/_describe b/Completion/Base/_describe index e59dc1593..5355e4d7f 100644 --- a/Completion/Base/_describe +++ b/Completion/Base/_describe @@ -2,15 +2,19 @@ # This can be used to add options or values with descriptions as matches. -local isopt cmd opt expl tmps tmpd tmpmd tmpms ret=1 showd _nm hide +local cmd func opt expl tmps tmpd tmpmd tmpms ret=1 showd _nm hide +local prios tags type=value cmd="$words[1]" +func="$funcstack[2]" # Get the options. -while getopts 'oc:' opt; do +while getopts 'oc:f:' opt; do if [[ "$opt" = o ]]; then - isopt=yes + type=option + elif [[ "$opt" = f ]]; then + func="$OPTARG" else cmd="$OPTARG" fi @@ -19,28 +23,11 @@ shift OPTIND-1 # Do the tests. `showd' is set if the descriptions should be shown. -if [[ -n "$isopt" ]]; then +_tags -c "$cmd" -f "$func" "$type" - # We take the value to test the number of matches from a non-local - # parameter `nm' if that exists and contains only digits. It's a hack. +_tags || return 1 - if [[ "$nm" = [0-9]## ]]; then - _nm="$nm" - else - _nm=0 - fi - [[ -n "$compconfig[option_prefix]" && - "$compconfig[option_prefix]" != *\!${cmd}* && - "$PREFIX" != [-+]* && - ( "$compconfig[option_prefix]" = *nodefault* || - _nm -ne compstate[nmatches] ) ]] && return 1 - - [[ -n "$compconfig[describe_options]" && - "$compconfig[describe_options]" != *\!${cmd}* ]] && showd=yes -else - [[ -n "$compconfig[describe_values]" && - "$compconfig[describe_values]" != *\!${cmd}* ]] && showd=yes -fi +[[ "$tags" = *:${type}\[*describe*\]* ]] && showd=yes _description expl "$1" shift @@ -51,7 +38,7 @@ else compdescribe -i "$@" fi -[[ -n "$isopt" && "$compconfig[option_prefix]" = hide* ]] && hide=yes +[[ "$type" = option && "$tags" = *:option\[*hide*\]* ]] && hide=yes while compdescribe -g args tmpd tmpmd tmps tmpms; do diff --git a/Completion/Base/_values b/Completion/Base/_values index e4ef8af68..34a5c4097 100644 --- a/Completion/Base/_values +++ b/Completion/Base/_values @@ -2,9 +2,13 @@ if compvalues -i "$@"; then - local noargs args opts descr action expl sep + local tags prios noargs args opts descr action expl sep if ! compvalues -D descr action; then + + _tags value + _tags || return 1 + compvalues -V noargs args opts if [[ "$PREFIX" = *\=* ]]; then @@ -39,7 +43,7 @@ if compvalues -i "$@"; then sep=() fi - _describe "$descr" \ + _describe -f "$funcstack[2]" "$descr" \ noargs "$sep[@]" -M 'r:|[_-]=* r:|=*' -- \ args -S= -M 'r:|[_-]=* r:|=*' -- \ opts -qS= -M 'r:|[_-]=* r:|=*' @@ -48,6 +52,9 @@ if compvalues -i "$@"; then fi fi + _tags argument + _tags || return 1 + _description expl "$descr" # We add the separator character as a autoremovable suffix unless @@ -80,7 +87,7 @@ if compvalues -i "$@"; then eval ws\=\( "${action[3,-3]}" \) - _describe "$descr" ws -M 'r:|[_-]=* r:|=*' + _describe -f "$funcstack[2]" "$descr" ws -M 'r:|[_-]=* r:|=*' elif [[ "$action" = \(*\) ]]; then |