From 9597b7505ab1cf64c246b4a32e14b0602c36b1b2 Mon Sep 17 00:00:00 2001 From: Tanaka Akira Date: Thu, 14 Oct 1999 15:05:40 +0000 Subject: manual/8249 --- Completion/Builtins/_nothing | 3 +++ Completion/Core/_description | 2 ++ Completion/Core/_files | 9 ++++--- Completion/Core/_main_complete | 20 ++++++++++++++++ Completion/Core/_message | 5 ++-- Completion/Core/_multi_parts | 53 ++++++++++++++++++++++++------------------ Completion/Core/_path_files | 38 +++++++++++++++++------------- Completion/Core/_sep_parts | 12 ++++++---- 8 files changed, 94 insertions(+), 48 deletions(-) create mode 100644 Completion/Builtins/_nothing (limited to 'Completion') diff --git a/Completion/Builtins/_nothing b/Completion/Builtins/_nothing new file mode 100644 index 000000000..35a2558cc --- /dev/null +++ b/Completion/Builtins/_nothing @@ -0,0 +1,3 @@ +#compdef true false + +_message 'no argument or option' diff --git a/Completion/Core/_description b/Completion/Core/_description index a19a8373c..107be5cd6 100644 --- a/Completion/Core/_description +++ b/Completion/Core/_description @@ -7,6 +7,8 @@ if [[ "$1" = -[VJ]* ]]; then shift fi +_lastdescr=( "$_lastdescr[@]" "$2" ) + if [[ -n "$compconfig[group_matches]" ]]; then if [[ -n "$compconfig[description_format]" ]]; then eval "$1=($gropt ${(q)2} -X ${(q)compconfig[description_format]//\\%d/$2})" diff --git a/Completion/Core/_files b/Completion/Core/_files index b6349a8c5..38eafd196 100644 --- a/Completion/Core/_files +++ b/Completion/Core/_files @@ -17,9 +17,12 @@ if [[ $# -ne 0 && compstate[nmatches] -eq nm ]]; then # files and give up immediatly. opts=() - while getopts "P:S:W:F:J:V:X:f/g:" opt; do - [[ "$opt" = f ]] && return - [[ "$opt" = [PSWFJVX] ]] && opts=("$opts[@]" "-$opt" "$OPTARG") + while getopts "P:S:qr:R:W:F:J:V:X:f/g:M:" opt; do + case "$opt" in + f) return;; + [PSrRWFJVXM]) opts=("$opts[@]" "-$opt" "$OPTARG");; + q) opts=("$opts[@]" -q);; + esac done _path_files "$opts[@]" && ret=0 diff --git a/Completion/Core/_main_complete b/Completion/Core/_main_complete index 330eb9161..4496f5bda 100644 --- a/Completion/Core/_main_complete +++ b/Completion/Core/_main_complete @@ -24,6 +24,8 @@ local comp ret=1 _compskip +typeset -U _lastdescr + setopt localoptions nullglob rcexpandparam unsetopt markdirs globsubst shwordsplit nounset ksharrays @@ -56,6 +58,24 @@ for post in "$comppostfuncs[@]"; do done comppostfuncs=() +_lastdescr=( "\`${(@)^_lastdescr:#}'" ) +if [[ compstate[nmatches] -eq 0 && + -n "$compconfig[warning_format]" && $#_lastdescr -ne 0 ]]; then + local str + + compstate[list]=list + compstate[force_list]=yes + compstate[insert]='' + + case $#_lastdescr in + 1) str="$_lastdescr[1]";; + 2) str="$_lastdescr[1] or $_lastdescr[2]";; + *) str="${(j:, :)_lastdescr[1,-2]}, or $_lastdescr[-1]";; + esac + + compadd -UX "${compconfig[warning_format]//\\%d/$str}" -n '' +fi + [[ "$compconfig[last_prompt]" = always ]] && compstate[last_prompt]=yes _lastcomp=( "${(@kv)compstate}" ) diff --git a/Completion/Core/_message b/Completion/Core/_message index b7cb34ee1..ab1c67992 100644 --- a/Completion/Core/_message +++ b/Completion/Core/_message @@ -2,15 +2,14 @@ local format -format="$compconfig[message_format]" -[[ -z "$format" ]] && format="$compconfig[description_format]" +format="${compconfig[message_format]:-$compconfig[description_format]}" if [[ -n "$format" ]]; then if [[ $compstate[nmatches] -eq 0 ]]; then compstate[list]=list + compstate[force_list]=yes compstate[insert]='' compadd -UX "${format//\\%d/$1}" -n '' - compstate[force_list]=yes else compadd -X "${format//\\%d/$1}" -n '' && compstate[force_list]=yes fi diff --git a/Completion/Core/_multi_parts b/Completion/Core/_multi_parts index 30a68d312..e842db754 100644 --- a/Completion/Core/_multi_parts +++ b/Completion/Core/_multi_parts @@ -8,16 +8,24 @@ # separator character are then completed independently. local sep matches pref npref i tmp1 group expl menu pre suf opre osuf cpre +local opts sopts match typeset -U tmp2 # Get the options. group=() expl=() -while getopts "J:V:X:" opt; do +opts=() +sopts=() +while getopts "J:V:X:P:S:r:R:qM:" opt; do case "$opt" in - [JV]) group=("-$opt" "$OPTARG");; - X) expl=(-X "$OPTARG");; + [JV]) group=("-$opt" "$OPTARG");; + X) expl=(-X "$OPTARG");; + P) opts=( "$opts[@]" -P "$OPTARG") + sopts=( "$sopts[@]" -P "$OPTARG");; + [SrR]) sopts=( "$sopts[@]" -P "$OPTARG");; + q) sopts=( "$sopts[@]" -q);; + M) match="$OPTARG";; esac done shift OPTIND-1 @@ -57,7 +65,7 @@ pref='' # If the string from the line matches at least one of the strings, # we use only the matching strings. -compadd -O tmp1 -M "r:|${sep}=* r:|=*" - "$matches[@]" +compadd -O tmp1 -M "r:|${sep}=* r:|=* $match" - "$matches[@]" (( $#tmp1 )) && matches=( "$tmp1[@]" ) @@ -106,11 +114,11 @@ while true; do SUFFIX="$suf" if (( $#tmp2 )); then - compadd "$group[@]" "$expl[@]" -p "$pref" -qS "$sep" \ - -M "r:|${sep}=* r:|=*" - "$tmp1[1]" + compadd "$group[@]" "$expl[@]" -p "$pref" -qS "$sep" "$opts[@]" \ + -M "r:|${sep}=* r:|=* $match" - "$tmp1[1]" else - compadd "$group[@]" "$expl[@]" -p "$pref" \ - -M "r:|${sep}=* r:|=*" - "$tmp1[1]" + compadd "$group[@]" "$expl[@]" -p "$pref" "$sopts[@]" \ + -M "r:|${sep}=* r:|=* $match" - "$tmp1[1]" fi return 0 fi @@ -121,7 +129,7 @@ while true; do PREFIX="$pre" SUFFIX="$suf" - compadd -O matches -M "r:|${sep}=* r:|=*" - "$matches[@]" + compadd -O matches -M "r:|${sep}=* r:|=* $match" - "$matches[@]" if [[ "$pre" = *${sep}* ]]; then PREFIX="${cpre}${pre%%${sep}*}" @@ -138,12 +146,12 @@ while true; do tmp2="$pre$suf" if [[ "$tmp2" = *${sep}* ]]; then - compadd "$group[@]" "$expl[@]" \ + compadd "$group[@]" "$expl[@]" "$sopts[@]" \ -p "$pref" -s "${sep}${tmp2#*${sep}}" \ - -M "r:|${sep}=* r:|=*" - "$tmp1[@]" + -M "r:|${sep}=* r:|=* $match" - "$tmp1[@]" else - compadd "$group[@]" "$expl[@]" -p "$pref"\ - -M "r:|${sep}=* r:|=*" - "$tmp1[@]" + compadd "$group[@]" "$expl[@]" -p "$pref" "$sopts[@]" \ + -M "r:|${sep}=* r:|=* $match" - "$tmp1[@]" fi else # With normal completion we add all matches one-by-one with @@ -152,12 +160,12 @@ while true; do for i in "${(@M)matches:#(${(j:|:)~tmp1})*}"; do if [[ "$i" = *${sep}* ]]; then - compadd "$group[@]" "$expl[@]" -S '' \ + compadd "$group[@]" "$expl[@]" -S '' "$opts[@]" \ -p "$pref" -s "${i#*${sep}}" \ - -M "r:|${sep}=* r:|=*" - "${i%%${sep}*}${sep}" + -M "r:|${sep}=* r:|=* $match" - "${i%%${sep}*}${sep}" else - compadd "$group[@]" "$expl[@]" -S '' -p "$pref" \ - -M "r:|${sep}=* r:|=*" - "$i" + compadd "$group[@]" "$expl[@]" -S '' "$opts[@]" -p "$pref" \ + -M "r:|${sep}=* r:|=* $match" - "$i" fi done fi @@ -173,11 +181,11 @@ while true; do SUFFIX="$suf" if [[ -n "$suf" ]]; then - compadd "$group[@]" "$expl[@]" -s "$suf" \ - -M "r:|${sep}=* r:|=*" - "$pref$pre" + compadd "$group[@]" "$expl[@]" -s "$suf" "$sopts[@]" \ + -M "r:|${sep}=* r:|=* $match" - "$pref$pre" else - compadd "$group[@]" "$expl[@]" -S '' \ - -M "r:|${sep}=* r:|=*" - "$pref$pre" + compadd "$group[@]" "$expl[@]" -S '' "$opts[@]" \ + -M "r:|${sep}=* r:|=* $match" - "$pref$pre" fi return 0 fi @@ -208,7 +216,8 @@ while true; do SUFFIX="" [[ -n "$pref" && "$orig" != "$pref" ]] && - compadd "$group[@]" "$expl[@]" -S '' -M "r:|${sep}=* r:|=*" - "$pref" + compadd "$group[@]" "$expl[@]" -S '' "$opts[@]" \ + -M "r:|${sep}=* r:|=* $match" - "$pref" return fi diff --git a/Completion/Core/_path_files b/Completion/Core/_path_files index 455de444d..eb9c06da6 100644 --- a/Completion/Core/_path_files +++ b/Completion/Core/_path_files @@ -6,7 +6,7 @@ local linepath realpath donepath prepath testpath exppath local tmp1 tmp2 tmp3 tmp4 i orig pre suf tpre tsuf opre osuf cpre local pats haspats=no ignore group expl addpfx addsfx remsfx -local nm=$compstate[nmatches] menu +local nm=$compstate[nmatches] menu match matcher typeset -U prepaths exppaths @@ -23,10 +23,11 @@ addpfx=() addsfx=() remsfx=() expl=() +matcher=() # Get the options. -while getopts "P:S:qr:R:W:F:J:V:X:f/g:" opt; do +while getopts "P:S:qr:R:W:F:J:V:X:f/g:M:" opt; do case "$opt" in P) addpfx=(-P "$OPTARG") ;; @@ -68,6 +69,9 @@ while getopts "P:S:qr:R:W:F:J:V:X:f/g:" opt; do pats=("$pats[@]" ${=OPTARG}) haspats=yes ;; + M) match="$OPTARG" + matcher=(-M "$OPTARG") + ;; esac done @@ -124,9 +128,11 @@ if [[ -z "$suf" && $#ignore -eq 0 && $#remsfx -eq 0 && # Now call compgen. if [[ -z "$gopt" ]]; then - compgen "$addpfx[@]" "$addsfx[@]" "$group[@]" "$expl[@]" "$tmp1[@]" $sopt + compgen "$addpfx[@]" "$addsfx[@]" "$group[@]" "$expl[@]" \ + "$tmp1[@]" "$matcher[@]" $sopt else - compgen "$addpfx[@]" "$addsfx[@]" "$group[@]" "$expl[@]" "$tmp1[@]" $sopt -g "$pats" + compgen "$addpfx[@]" "$addsfx[@]" "$group[@]" "$expl[@]" \ + "$tmp1[@]" "$matcher[@]" $sopt -g "$pats" fi # If this generated any matches, we don't want to do in-path completion. @@ -243,7 +249,7 @@ for prepath in "$prepaths[@]"; do # See which of them match what's on the line. tmp2=("$tmp1[@]") - compadd -D tmp1 "$ignore[@]" - "${(@)tmp1:t}" + compadd -D tmp1 "$ignore[@]" "$matcher[@]" - "${(@)tmp1:t}" # If no file matches, save the expanded path and continue with # the outer loop. @@ -346,14 +352,14 @@ for prepath in "$prepaths[@]"; do if [[ "$tmp3" = */* ]]; then compadd -Qf -p "$linepath${testpath:q}" -s "/${tmp3#*/}" \ -W "$prepath$realpath$testpath" "$ignore[@]" \ - "$addpfx[@]" "$addsfx[@]" "$remsfx[@]" -M 'r:|/=* r:|=*' \ - "$group[@]" "$expl[@]" \ + "$addpfx[@]" "$addsfx[@]" "$remsfx[@]" \ + -M "r:|/=* r:|=* $match" "$group[@]" "$expl[@]" \ - "${(@)${(@)tmp1%%/*}:q}" else compadd -Qf -p "$linepath${testpath:q}" \ -W "$prepath$realpath$testpath" "$ignore[@]" \ - "$addpfx[@]" "$addsfx[@]" "$remsfx[@]" -M 'r:|/=* r:|=*' \ - "$group[@]" "$expl[@]" \ + "$addpfx[@]" "$addsfx[@]" "$remsfx[@]" \ + -M "r:|/=* r:|=* $match" "$group[@]" "$expl[@]" \ - "${(@)tmp1:q}" fi else @@ -361,15 +367,15 @@ for prepath in "$prepaths[@]"; do for i in "$tmp1[@]"; do compadd -Qf -p "$linepath${testpath:q}" -s "/${${i#*/}:q}" \ -W "$prepath$realpath$testpath" "$ignore[@]" \ - "$addpfx[@]" "$addsfx[@]" "$remsfx[@]" -M 'r:|/=* r:|=*' \ - "$group[@]" "$expl[@]" \ + "$addpfx[@]" "$addsfx[@]" "$remsfx[@]" \ + -M "r:|/=* r:|=* $match" "$group[@]" "$expl[@]" \ - "${${i%%/*}:q}" done else compadd -Qf -p "$linepath${testpath:q}" \ -W "$prepath$realpath$testpath" "$ignore[@]" \ - "$addpfx[@]" "$addsfx[@]" "$remsfx[@]" -M 'r:|/=* r:|=*' \ - "$group[@]" "$expl[@]" \ + "$addpfx[@]" "$addsfx[@]" "$remsfx[@]" \ + -M "r:|/=* r:|=* $match" "$group[@]" "$expl[@]" \ - "${(@)tmp1:q}" fi fi @@ -400,8 +406,8 @@ for prepath in "$prepaths[@]"; do SUFFIX="" compadd -Qf -p "$linepath${testpath:q}" \ -W "$prepath$realpath$testpath" "$ignore[@]" \ - "$addpfx[@]" "$addsfx[@]" "$remsfx[@]" -M 'r:|/=* r:|=*' \ - "$group[@]" "$expl[@]" \ + "$addpfx[@]" "$addsfx[@]" "$remsfx[@]" \ + -M "r:|/=* r:|=* $match" "$group[@]" "$expl[@]" \ - "${(@)tmp1:q}" fi done @@ -417,7 +423,7 @@ if [[ -n "$compconfig[path_expand]" && PREFIX="${opre}${osuf}" SUFFIX="" compadd -Q -S '' "$group[@]" "$expl[@]" \ - -M 'r:|/=* r:|=*' -p "$linepath" - "$exppaths[@]" + -M "r:|/=* r:|=* $match" -p "$linepath" - "$exppaths[@]" fi [[ nm -ne compstate[nmatches] ]] diff --git a/Completion/Core/_sep_parts b/Completion/Core/_sep_parts index 0a8cae28f..c65a944e3 100644 --- a/Completion/Core/_sep_parts +++ b/Completion/Core/_sep_parts @@ -18,16 +18,20 @@ # `-X explanation' options. local str arr sep test testarr tmparr prefix suffixes matchers autosuffix -local matchflags opt group expl nm=$compstate[nmatches] opre osuf +local matchflags opt group expl nm=$compstate[nmatches] opre osuf opts match # Get the options. group=() expl=() -while getopts "J:V:X:" opt; do +opts=() +while getopts "J:V:X:P:S:r:R:qM:" opt; do case "$opt" in [JV]) group=("-$opt" "$OPTARG");; X) expl=(-X "$OPTARG");; + q) opts=( "$opts[@]" -q );; + M) match="$OPTARG";; + *) opts=( "$opts[@]" "-$opt" "$OPTARG" );; esac done shift OPTIND-1 @@ -142,14 +146,14 @@ done # If we have collected matching specifications, we build an array # from it that can be used as arguments to `compadd'. -[[ $#matchers -gt 0 ]] && matchers=(-M "$matchers") +[[ $#matchers+$#match -gt 0 ]] && matchers=(-M "$matchers $match") # Add the matches for each of the suffixes. PREFIX="$pre" SUFFIX="$suf" for i in "$suffixes[@]"; do - compadd -U "$group[@]" "$expl[@]" "$matchers[@]" "$autosuffix[@]" \ + compadd -U "$group[@]" "$expl[@]" "$matchers[@]" "$autosuffix[@]" "$opts[@]" \ -i "$IPREFIX" -I "$ISUFFIX" -p "$prefix" -s "$i" - "$testarr[@]" done -- cgit 1.4.1