summaryrefslogtreecommitdiffstats
path: root/Completion/Base
diff options
context:
space:
mode:
authorTanaka Akira <akr@users.sourceforge.net>1999-09-15 14:35:16 +0000
committerTanaka Akira <akr@users.sourceforge.net>1999-09-15 14:35:16 +0000
commitbc9e764f4e9b95ec4c2a855c4118f6afb994e904 (patch)
treecba20ce3f39ef0f1916ddd3be6a7aa9250e3dc8f /Completion/Base
parentzsh-workers/7840 (diff)
downloadzsh-bc9e764f4e9b95ec4c2a855c4118f6afb994e904.tar
zsh-bc9e764f4e9b95ec4c2a855c4118f6afb994e904.tar.gz
zsh-bc9e764f4e9b95ec4c2a855c4118f6afb994e904.tar.bz2
zsh-bc9e764f4e9b95ec4c2a855c4118f6afb994e904.tar.lz
zsh-bc9e764f4e9b95ec4c2a855c4118f6afb994e904.tar.xz
zsh-bc9e764f4e9b95ec4c2a855c4118f6afb994e904.tar.zst
zsh-bc9e764f4e9b95ec4c2a855c4118f6afb994e904.zip
zsh-workers/7844
Diffstat (limited to 'Completion/Base')
-rw-r--r--Completion/Base/_arguments73
-rw-r--r--Completion/Base/_describe155
-rw-r--r--Completion/Base/_subscript4
-rw-r--r--Completion/Base/_tilde4
-rw-r--r--Completion/Base/_values41
5 files changed, 194 insertions, 83 deletions
diff --git a/Completion/Base/_arguments b/Completion/Base/_arguments
index a8e272cac..df01ba6a4 100644
--- a/Completion/Base/_arguments
+++ b/Completion/Base/_arguments
@@ -8,7 +8,7 @@ setopt localoptions extendedglob
local args rest ws cur nth def nm expl descr action opt arg tmp xor
local single uns ret=1 aret soptseq soptseq1 sopts prefix _line odescr
local beg optbeg argbeg nargbeg inopt inrest fromrest cmd="$words[1]"
-local matched curopt noargs i
+local matched curopt noargs i tmp1 tmp2 tmp3 suffix
# Associative arrays used to collect information about the options.
@@ -793,13 +793,8 @@ while true; do
eval ws\=\( "${action[3,-3]}" \)
- if [[ -n "$compconfig[describe_values]" &&
- "$compconfig[describe_values]" != *\!${cmd}* ]] &&
- _display tmp "$ws[@]"; then
- compadd "$expl[@]" -M 'r:|[_-]=* r:|=*' -ld tmp - "${(@)ws%%:*}"
- else
- compadd "$expl[@]" - "${(@)ws%%:*}"
- fi
+ _describe -c "$cmd" "$descr" ws -M 'r:|[_-]=* r:|=*'
+
elif [[ "$action" = \(*\) ]]; then
# Anything inside `(...)' is added directly.
@@ -837,62 +832,36 @@ while true; do
if [[ -n "$sopts" && -n "$PREFIX" &&
"$PREFIX" = [-+]${~soptseq}[$sopts] ]]; then
if [[ "$PREFIX" = [-+]${~soptseq1} ]]; then
- if [[ -z "$compconfig[describe_options]" ||
- "$compconfig[describe_options]" = *\!${cmd}* ]]; then
- tmp=( "${PREFIX[1]}${(@)^${(@)${(@M)${=:-${(k)opts} ${(k)dopts} ${(k)odopts}}:#[-+]?(|=)}#?}%=}" )
- compadd "$expl[@]" -Q -M 'r:|[_-]=* r:|=*' -d tmp - \
- "${PREFIX}${(@k)^opts[(I)${PREFIX[1]}?]#?}" \
- "${PREFIX}${(@k)^dopts[(I)${PREFIX[1]}?]#?}" \
- "${PREFIX}${(@)^${(@k)odopts[(I)${PREFIX[1]}?(|=)]#?}%=}" &&
- ret=0
- elif _display tmp "${(@Mo)odescr:#[-+]?:*}"; then
- compadd "$expl[@]" -Q -M 'r:|[_-]=* r:|=*' -ld tmp - \
- "${PREFIX}${(@)^${(@)${(@Mo)odescr:#[-+]?:*}%%:*}#?}" && ret=0
- else
- compadd "$expl[@]" -Q -M 'r:|[_-]=* r:|=*' -d tmp - \
- "${PREFIX}${(@)^${(@)${(@Mo)odescr:#[-+]?:*}%%:*}#?}" && ret=0
- fi
+ tmp1=( "${(@Mo)odescr:#[-+]?:*}" )
+ tmp2=(
+ "${PREFIX}${(@k)^opts[(I)${PREFIX[1]}?]#?}" \
+ "${PREFIX}${(@k)^dopts[(I)${PREFIX[1]}?]#?}" \
+ "${PREFIX}${(@)^${(@k)odopts[(I)${PREFIX[1]}?(|=)]#?}%=}"
+ )
+ tmp2=( "${(@o)tmp2}" )
+
+ _describe -o -c "$cmd" option \
+ tmp1 tmp2 -Q -M 'r:|[_-]=* r:|=*'
else
# The last option takes an argument in the next word.
compadd "$expl[@]" -Q -M 'r:|[_-]=* r:|=*' - "${PREFIX}" && ret=0
fi
else
- if [[ -n "$compconfig[describe_options]" &&
- "$compconfig[describe_options]" != *\!${cmd}* ]] &&
- _display descr "$odescr[@]"; then
- ws=( "${(k)opts[@]}" "${(@k)odopts[(I)*[^=]]}" )
- if (( $#ws )); then
- tmp=( "${(@M)descr:#(${(j:|:)~ws}) *}" )
- compadd "$expl[@]" -Q -M 'r:|[_-]=* r:|=*' -ld tmp - \
- "$ws[@]" && ret=0
- fi
- if (( $#dopts )); then
- tmp=( "${(@M)descr:#(${(kj:|:)~dopts}) *}" )
- compadd "$expl[@]" -QS '' -M 'r:|[_-]=* r:|=*' -ld tmp - \
- "${(@k)dopts}" && ret=0
- fi
- if (( ${(@k)#odopts[(I)*=]} )); then
- tmp=( "${(@M)descr:#(${(kj:|:)~odopts[(I)*=]}) *}" )
- compadd "$expl[@]" -QqS= -M 'r:|[_-]=* r:|=*' -ld tmp - \
- "${(@k)odopts[(I)*=]%=}" && ret=0
- fi
- else
- compadd "$expl[@]" -Q -M 'r:|[_-]=* r:|=*' - \
- "${(@k)opts}" "${(@k)odopts[(I)*[^=]]}" && ret=0
- compadd "$expl[@]" -QqS= -M 'r:|[_-]=* r:|=*' - \
- "${(@k)odopts[(I)*=]%=}" && ret=0
- compadd "$expl[@]" -QS '' -M 'r:|[_-]=* r:|=*' - \
- "${(@k)dopts}" && ret=0
- fi
+ tmp1=( "${(k)opts[@]}" "${(@k)odopts[(I)*[^=]]}" )
+ tmp1=( "${(@M)odescr:#(${(kj:|:)~tmp1}):*}" )
+ tmp2=( "${(@M)odescr:#(${(kj:|:)~dopts}):*}" )
+ tmp3=( "${(@M)odescr:#(${(kj:|:)~odopts[(I)*=]}):*}" )
+ _describe -o -c "$cmd" option \
+ tmp1 -Q -M 'r:|[_-]=* r:|=*' -- \
+ tmp2 -QS '' -M 'r:|[_-]=* r:|=*' -- \
+ tmp3 -QqS= -M 'r:|[_-]=* r:|=*'
fi
fi
if [[ nm -eq compstate[nmatches] &&
( -z "$single" ||
( $#_args_cache_long -ne 0 && "$PREFIX" = --*=* ) ) ]]; then
- local suffix
-
tmp=( "${(@Mk)odopts:#[^:]#\=}" )
prefix="${PREFIX#*\=}"
suffix="$SUFFIX"
diff --git a/Completion/Base/_describe b/Completion/Base/_describe
new file mode 100644
index 000000000..e01c77509
--- /dev/null
+++ b/Completion/Base/_describe
@@ -0,0 +1,155 @@
+#autoload
+
+# This can be used to add options or values with descriptions as matches.
+
+setopt localoptions extendedglob
+
+local gdescr isopt cmd opt nsets tmp descr match descrs matches adescr i
+local disps disp expl tmps tmpd tmpmd tmpms name ret=1 showd _nm
+
+cmd="$words[1]"
+
+# Get the options.
+
+while getopts 'oc:' opt; do
+ if [[ "$opt" = o ]]; then
+ isopt=yes
+ else
+ cmd="$OPTARG"
+ fi
+done
+shift OPTIND-1
+
+# Do the tests. `showd' is set if the descriptions should be shown.
+
+if [[ -n "$isopt" ]]; then
+
+ # We take the value to test the number of patches from a non-local
+ # parameter `nm' if that exists and contains only digits. It's a hack.
+
+ 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
+
+gdescr="$1"
+shift
+
+# Now interpret the arguments.
+
+nsets=0
+adescr=()
+descrs=()
+matches=()
+while (( $# )); do
+ (( nsets++ ))
+ descr="$1"
+ [[ -n "$showd" ]] && adescr=( "$adescr[@]" "${(@PM)^descr:#*:?*},$nsets" )
+ if [[ "$2" = -* ]]; then
+ match=''
+ shift
+ else
+ match="$2"
+ shift 2
+ fi
+ tmp=$argv[(i)--]
+ if [[ tmp -eq 1 ]]; then
+ opt=()
+ else
+ opt=( "${(@)argv[1,tmp-1]}" )
+ fi
+ if [[ tmp -gt $# ]]; then
+ argv=()
+ else
+ shift tmp
+ fi
+
+ # `descr' and `matches' collect the names of the arrays containing the
+ # possible matches with descriptions and the matches to add.
+ # The options to give to `compadd' are stored in local arrays.
+
+ descrs[nsets]="$descr"
+ matches[nsets]="$match"
+ typeset -a _descr_opts_$nsets
+ eval "_descr_opts_${nsets}=( \"\$opt[@]\" )"
+done
+
+(( nsets )) || return 1
+
+# Build the display strings if needed.
+
+[[ -n "$showd" ]] && _display disps "$adescr[@]"
+_description expl "$gdescr"
+
+# Loop through the array/option sets we have.
+
+i=0
+while [[ ++i -le nsets ]]; do
+ name=_descr_opts_$i
+ [[ -n "$showd" ]] && disp=( "${(@)${(@M)disps:#*,${i}}%,*}" )
+ descr=( "${(@P)descrs[i]}" )
+
+ # We collect the strings to display in `tmpd' (one string per line)
+ # and `tmps' (in columns) and the matches to add in `tmpmd' and `tmpms'.
+
+ tmpd=()
+ tmps=()
+ tmpmd=()
+ tmpms=()
+ if [[ -n "$matches[i]" ]]; then
+ match=( "${(@P)matches[i]}" )
+ while (( $#match )); do
+ if [[ -n "$showd" && "$descr[1]" = *:?* ]]; then
+ tmpd=( "$tmpd[@]" "$disp[1]" )
+ tmpmd=( "$tmpmd[@]" "$match[1]" )
+ shift 1 disp
+ else
+ tmps=( "$tmps[@]" "${descr[1]%%:*}" )
+ tmpms=( "$tmpms[@]" "$match[1]" )
+ fi
+ shift 1 match
+ shift 1 descr
+ done
+ else
+ while (( $#descr )); do
+ if [[ -n "$showd" && "$descr[1]" = *:?* ]]; then
+ tmpd=( "$tmpd[@]" "$disp[1]" )
+ tmpmd=( "$tmpmd[@]" "${descr[1]%%:*}" )
+ shift 1 disp
+ else
+ tmps=( "$tmps[@]" "${descr[1]%%:*}" )
+ tmpms=( "$tmpms[@]" "${descr[1]%%:*}" )
+ fi
+ shift 1 descr
+ done
+ fi
+
+ # See if we should remove the option prefix characters.
+
+ if [[ -n "$isopt" && "$compconfig[option_prefix]" = hide* ]]; then
+ if [[ "$PREFIX" = --* ]]; then
+ tmpd=( "${(@)tmpd#--}" )
+ tmps=( "${(@)tmps#--}" )
+ elif [[ "$PREFIX" = [-+]* ]]; then
+ tmpd=( "${(@)tmpd#[-+]}" )
+ tmps=( "${(@)tmps#[-+]}" )
+ fi
+ fi
+ compadd "${(@P)name}" "$expl[@]" -ld tmpd - "$tmpmd[@]" && ret=0
+ compadd "${(@P)name}" "$expl[@]" -d tmps - "$tmpms[@]" && ret=0
+done
+
+return ret
diff --git a/Completion/Base/_subscript b/Completion/Base/_subscript
index 76644bafb..803893912 100644
--- a/Completion/Base/_subscript
+++ b/Completion/Base/_subscript
@@ -26,9 +26,9 @@ elif [[ ${(Pt)${compstate[parameter]}} = array* ]]; then
done
if [[ "$RBUFFER" = \]* ]]; then
- compadd "$expl[@]" -S '' -V default -y list - "$ind[@]"
+ compadd "$expl[@]" -S '' -V default -d list - "$ind[@]"
else
- compadd "$expl[@]" -S ']' -V default -y list - "$ind[@]"
+ compadd "$expl[@]" -S ']' -V default -d list - "$ind[@]"
fi
else
_compalso -math-
diff --git a/Completion/Base/_tilde b/Completion/Base/_tilde
index b8d639074..95d342538 100644
--- a/Completion/Base/_tilde
+++ b/Completion/Base/_tilde
@@ -9,7 +9,7 @@
setopt localoptions extendedglob
-local d s dirs list
+local d s dirs list lines
if [[ "$SUFFIX" = */* ]]; then
ISUFFIX="/${SUFFIX#*/}$ISUFFIX"
@@ -36,7 +36,7 @@ if [[ -prefix [-+] ]]; then
compset -P '[-+]'
_description d 'directory stack'
- compadd "$d[@]" -d lines -Q - "$list[@]"
+ compadd "$d[@]" -ld lines -Q - "$list[@]"
else
if (( $# )); then
d=( "$@" )
diff --git a/Completion/Base/_values b/Completion/Base/_values
index 21f6908cc..5b413313b 100644
--- a/Completion/Base/_values
+++ b/Completion/Base/_values
@@ -3,7 +3,7 @@
setopt localoptions extendedglob
local name arg def descr xor str tmp ret=1 expl nm="$compstate[nmatches]"
-local snames odescr gdescr sep esep spat
+local snames odescr gdescr sep esep spat tmp1 tmp2 tmp3 opts
typeset -A names onames xors _values
# Probably fill our cache.
@@ -280,34 +280,21 @@ else
# No `=', just complete value names.
- _description expl "$gdescr"
-
- [[ -n "$sep" && ${#snames}+${#names}+${#onames} -ne 1 ]] &&
- expl=( "-qS$sep" "$expl[@]" )
-
- if [[ -n "$compconfig[describe_values]" &&
- "$compconfig[describe_values]" != *\!${words[1]}* ]] &&
- _display descr "$odescr[@]"; then
- if (( $#snames )); then
- tmp=( "${(@M)descr:#(${(j:|:)~snames}) *}" )
- compadd "$expl[@]" -ld tmp -M 'r:|[_-]=* r:|=*' - \
- "${(@)tmp%% *}" && ret=0
- fi
- if (( $#names )); then
- tmp=( "${(@M)descr:#(${(kj:|:)~names}) *}" )
- compadd -S= "$expl[@]" -ld tmp -M 'r:|[_-]=* r:|=*' - \
- "${(@)tmp%% *}" && ret=0
- fi
- if (( $#onames )); then
- tmp=( "${(@M)descr:#(${(kj:|:)~onames}) *}" )
- compadd -qS= "$expl[@]" -ld tmp -M 'r:|[_-]=* r:|=*' - \
- "${(@)tmp%% *}" && ret=0
- fi
+ if [[ -n "$sep" && ${#snames}+${#names}+${#onames} -ne 1 ]]; then
+ opts=( "-qS$sep" )
else
- compadd "$expl[@]" -M 'r:|[_-]=* r:|=*' - "$snames[@]" && ret=0
- compadd -S= "$expl[@]" -M 'r:|[_-]=* r:|=*' - "${(@k)names}" && ret=0
- compadd -qS= "$expl[@]" -M 'r:|[_-]=* r:|=*' - "${(@k)onames}" && ret=0
+ opts=()
fi
+
+ tmp1=( "${(@M)odescr:#(${(j:|:)~snames}):*}" )
+ tmp2=( "${(@M)odescr:#(${(kj:|:)~names}):*}" )
+ tmp3=( "${(@M)odescr:#(${(kj:|:)~onames}):*}" )
+
+ _describe "$gdescr" \
+ tmp1 "$opts[@]" -M 'r:|[_-]=* r:|=*' -- \
+ tmp2 -S= "$opts[@]" -M 'r:|[_-]=* r:|=*' -- \
+ tmp3 -qS= "$opts[@]" -M 'r:|[_-]=* r:|=*'
+
return ret
fi