mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-10-02 08:51:18 +02:00
users/6606: handle any matching control options passed down
This commit is contained in:
parent
5de7581394
commit
b598aba368
@ -1,5 +1,8 @@
|
|||||||
2003-09-21 Oliver Kiddle <opk@zsh.org>
|
2003-09-21 Oliver Kiddle <opk@zsh.org>
|
||||||
|
|
||||||
|
* users/6606: Completion/Base/Utility/_sep_parts: handle any
|
||||||
|
matching control options passed down
|
||||||
|
|
||||||
* 19106: Doc/Zsh/compsys.yo: document use for _menu
|
* 19106: Doc/Zsh/compsys.yo: document use for _menu
|
||||||
|
|
||||||
2003-09-17 Vin Shelton <acs@alumni.princeton.edu>
|
2003-09-17 Vin Shelton <acs@alumni.princeton.edu>
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
# This function understands the `-J group', `-V group', and
|
# This function understands the `-J group', `-V group', and
|
||||||
# `-X explanation' options.
|
# `-X explanation' options.
|
||||||
|
|
||||||
local str arr sep test testarr tmparr prefix suffixes matchers autosuffix
|
local str arr sep test testarr tmparr prefix suffixes autosuffix
|
||||||
local matchflags opt group expl nm=$compstate[nmatches] opre osuf opts matcher
|
local matchflags opt group expl nm=$compstate[nmatches] opre osuf opts matcher
|
||||||
|
|
||||||
# Get the options.
|
# Get the options.
|
||||||
@ -25,12 +25,6 @@ local matchflags opt group expl nm=$compstate[nmatches] opre osuf opts matcher
|
|||||||
zparseopts -D -a opts \
|
zparseopts -D -a opts \
|
||||||
'J+:=group' 'V+:=group' P: F: S: r: R: q 1 2 n 'X+:=expl' 'M+:=matcher'
|
'J+:=group' 'V+:=group' P: F: S: r: R: q 1 2 n 'X+:=expl' 'M+:=matcher'
|
||||||
|
|
||||||
if (( $#matcher )); then
|
|
||||||
matcher="${matcher[2]}"
|
|
||||||
else
|
|
||||||
matcher=''
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Get the string from the line.
|
# Get the string from the line.
|
||||||
|
|
||||||
opre="$PREFIX"
|
opre="$PREFIX"
|
||||||
@ -58,9 +52,9 @@ while [[ $# -gt 1 ]]; do
|
|||||||
# Get the matching array elements.
|
# Get the matching array elements.
|
||||||
|
|
||||||
PREFIX="${str%%(|\\)${sep}*}"
|
PREFIX="${str%%(|\\)${sep}*}"
|
||||||
builtin compadd -O testarr -a "$arr"
|
builtin compadd -O testarr "$matcher[@]" -a "$arr"
|
||||||
[[ $#testarr -eq 0 && -n "$_comp_correct" ]] &&
|
[[ $#testarr -eq 0 && -n "$_comp_correct" ]] &&
|
||||||
compadd -O testarr -a "$arr"
|
compadd -O testarr "$matcher[@]" -a "$arr"
|
||||||
|
|
||||||
# If there are no matches we give up. If there is more than one
|
# If there are no matches we give up. If there is more than one
|
||||||
# match, this is the part we will complete.
|
# match, this is the part we will complete.
|
||||||
@ -88,9 +82,9 @@ if [[ $# -le 1 || "$str" != *${2}* ]]; then
|
|||||||
# No more separators, build the matches.
|
# No more separators, build the matches.
|
||||||
|
|
||||||
PREFIX="$str"
|
PREFIX="$str"
|
||||||
builtin compadd -O testarr -a "$arr"
|
builtin compadd -O testarr "$matcher[@]" -a "$arr"
|
||||||
[[ $#testarr -eq 0 && -n "$_comp_correct" ]] &&
|
[[ $#testarr -eq 0 && -n "$_comp_correct" ]] &&
|
||||||
compadd -O testarr -a "$arr"
|
compadd -O testarr "$matcher[@]" -a "$arr"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
[[ $#testarr -eq 0 || ${#testarr[1]} -eq 0 ]] && return 1
|
[[ $#testarr -eq 0 || ${#testarr[1]} -eq 0 ]] && return 1
|
||||||
@ -98,7 +92,6 @@ fi
|
|||||||
# Now we build the suffixes to give to the completion code.
|
# Now we build the suffixes to give to the completion code.
|
||||||
|
|
||||||
shift
|
shift
|
||||||
matchers=()
|
|
||||||
suffixes=("")
|
suffixes=("")
|
||||||
autosuffix=()
|
autosuffix=()
|
||||||
|
|
||||||
@ -125,17 +118,12 @@ while [[ $# -gt 0 && "$str" == *${1}* ]]; do
|
|||||||
arr=tmparr
|
arr=tmparr
|
||||||
fi
|
fi
|
||||||
|
|
||||||
builtin compadd -O tmparr -a "$arr"
|
builtin compadd -O tmparr "$matcher[@]" -a "$arr"
|
||||||
[[ $#tmparr -eq 0 && -n "$_comp_correct" ]] &&
|
[[ $#tmparr -eq 0 && -n "$_comp_correct" ]] &&
|
||||||
compadd -O tmparr - "$arr"
|
compadd -O tmparr "$matcher[@]" - "$arr"
|
||||||
|
|
||||||
suffixes=("${(@)^suffixes[@]}${(q)1}${(@)^tmparr}")
|
suffixes=("${(@)^suffixes[@]}${(q)1}${(@)^tmparr}")
|
||||||
|
|
||||||
# We want the completion code to generate the most specific suffix
|
|
||||||
# for us, so we collect matching specifications that allow partial
|
|
||||||
# word matching before the separators on the fly.
|
|
||||||
|
|
||||||
matchers=("$matchers[@]" "r:|${1:q}=*")
|
|
||||||
shift 2
|
shift 2
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -144,17 +132,12 @@ done
|
|||||||
|
|
||||||
(( $# )) && autosuffix=(-qS "${(q)1}")
|
(( $# )) && autosuffix=(-qS "${(q)1}")
|
||||||
|
|
||||||
# If we have collected matching specifications, we build an array
|
|
||||||
# from it that can be used as arguments to `compadd'.
|
|
||||||
|
|
||||||
[[ $#matchers+$#matcher -gt 0 ]] && matchers=(-M "$matchers $matcher")
|
|
||||||
|
|
||||||
# Add the matches for each of the suffixes.
|
# Add the matches for each of the suffixes.
|
||||||
|
|
||||||
PREFIX="$pre"
|
PREFIX="$pre"
|
||||||
SUFFIX="$suf"
|
SUFFIX="$suf"
|
||||||
for i in "$suffixes[@]"; do
|
for i in "$suffixes[@]"; do
|
||||||
compadd -U "$group[@]" "$expl[@]" "$matchers[@]" "$autosuffix[@]" "$opts[@]" \
|
compadd -U "$group[@]" "$expl[@]" "$autosuffix[@]" "$opts[@]" \
|
||||||
-i "$IPREFIX" -I "$ISUFFIX" -p "$prefix" -s "$i" -a testarr
|
-i "$IPREFIX" -I "$ISUFFIX" -p "$prefix" -s "$i" -a testarr
|
||||||
done
|
done
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user