mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-09-03 10:21:46 +02:00
add -W option to _arguments, which allows to complete options after options that take an argument in the next word (13902)
This commit is contained in:
parent
ec01fb14b4
commit
163b0101ed
5 changed files with 41 additions and 13 deletions
|
@ -1,3 +1,11 @@
|
|||
2001-04-04 Sven Wischnowsky <wischnow@zsh.org>
|
||||
|
||||
* 13902: Completion/Base/Utility/_arguments,
|
||||
Completion/X/Utility/_x_arguments,
|
||||
Completion/X/Utility/_xt_arguments, Doc/Zsh/compsys.yo: add -W
|
||||
option to _arguments, which allows to complete options after
|
||||
options that take an argument in the next word
|
||||
|
||||
2000-04-03 Clint Adams <schizo@debian.org>
|
||||
|
||||
* 13899: Completion/Unix/Command/_apm: add $OSTYPE checking.
|
||||
|
|
|
@ -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 rawret
|
||||
local oldcontext="$curcontext" hasopts rawret optarg singopt
|
||||
|
||||
long=$argv[(I)--]
|
||||
if (( long )); then
|
||||
|
@ -173,18 +173,21 @@ if (( long )); then
|
|||
fi
|
||||
|
||||
subopts=()
|
||||
while [[ "$1" = -(O*|[CR]) ]]; do
|
||||
singopt=()
|
||||
while [[ "$1" = -(O*|[CRWs]) ]]; do
|
||||
case "$1" in
|
||||
-C) usecc=yes; shift ;;
|
||||
-O) subopts=( "${(@P)2}" ); shift 2 ;;
|
||||
-O*) subopts=( "${(@P)1[3,-1]}" ); shift ;;
|
||||
-R) rawret=yes; shift;;
|
||||
-W) optarg=yes; shift;;
|
||||
-s) singopt=(-s); shift;;
|
||||
esac
|
||||
done
|
||||
|
||||
zstyle -s ":completion:${curcontext}:options" auto-description autod
|
||||
|
||||
if (( $# )) && comparguments -i "$autod" "$@"; then
|
||||
if (( $# )) && comparguments -i "$autod" "$singopt[@]" "$@"; 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 anum
|
||||
|
@ -335,14 +338,19 @@ if (( $# )) && comparguments -i "$autod" "$@"; then
|
|||
if [[ "$single" = direct ]]; then
|
||||
_all_labels options expl option \
|
||||
compadd -QS '' - "${PREFIX}${SUFFIX}"
|
||||
elif [[ "$single" = next ]]; then
|
||||
elif [[ -z "$optarg" && "$single" = next ]]; then
|
||||
_all_labels options expl option \
|
||||
compadd -Q - "${PREFIX}${SUFFIX}"
|
||||
elif [[ "$single" = equal ]]; then
|
||||
_all_labels options expl option \
|
||||
compadd -QqS= - "${PREFIX}${SUFFIX}"
|
||||
else
|
||||
|
||||
tmp1=( "$next[@]" "$direct[@]" "$odirect[@]" "$equal[@]" )
|
||||
|
||||
[[ "$single" = next ]] &&
|
||||
tmp1=( "${(@)tmp1:#[-+]${PREFIX[-1]}((#e)|:*)}" )
|
||||
|
||||
[[ "$PREFIX" != --* ]] && tmp1=( "${(@)tmp1:#--*}" )
|
||||
tmp3=( "${(M@)tmp1:#[-+]?[^:]*}" )
|
||||
tmp1=( "${(M@)tmp1:#[-+]?(|:*)}" )
|
||||
|
@ -351,6 +359,11 @@ if (( $# )) && comparguments -i "$autod" "$@"; then
|
|||
_describe -o option \
|
||||
tmp1 tmp2 -Q -S '' -- \
|
||||
tmp3 -Q
|
||||
|
||||
[[ -n "$optarg" && "$single" = next && nm -eq $compstate[nmatches] ]] &&
|
||||
_all_labels options expl option \
|
||||
compadd -Q - "${PREFIX}${SUFFIX}"
|
||||
|
||||
fi
|
||||
single=yes
|
||||
else
|
||||
|
|
|
@ -17,7 +17,7 @@ else
|
|||
fi
|
||||
|
||||
opts=()
|
||||
while [[ $1 = -(O*|[CR]) ]]; do
|
||||
while [[ $1 = -(O*|[CRWs]) ]]; do
|
||||
opts=($opts $1)
|
||||
[[ $1 = -R ]] && rawret=yes
|
||||
shift
|
||||
|
|
|
@ -53,7 +53,7 @@ else
|
|||
fi
|
||||
|
||||
opts=()
|
||||
while [[ $1 = -(O*|[CR]) ]]; do
|
||||
while [[ $1 = -(O*|[CRWs]) ]]; do
|
||||
opts=($opts $1)
|
||||
[[ $1 = -R ]] && rawret=yes
|
||||
shift
|
||||
|
|
|
@ -2930,6 +2930,13 @@ two hyphens (like `tt(-)tt(-prefix)') are still considered to contain only
|
|||
one option name. This allows the use of the `tt(-s)' option to describe
|
||||
single-letter options together with such long option names.
|
||||
|
||||
The tt(-s) option may be combined with the option tt(-W) to say that more
|
||||
option characters are to be expected even after an option that takes an
|
||||
argument. For example, if a command takes the options `tt(a)' and `tt(b)',
|
||||
where `tt(a)' takes an argument in the next word, tt(_arguments) would
|
||||
normally not complete the other option directly after `tt(-a)', but it would
|
||||
allow that if given the tt(-W) option.
|
||||
|
||||
The forms of var(optspec) are:
|
||||
|
||||
startitem()
|
||||
|
@ -3202,6 +3209,13 @@ example(_arguments \
|
|||
- '(uncompress)' \
|
||||
{-d,--decompress}'[decompress]')
|
||||
|
||||
Note that using multiple sets will be slower than using only one set
|
||||
because the completion code has to parse the command line once for
|
||||
every set. So more than one set should only be used if the command
|
||||
syntax is too complicated. Note also that an option specification with
|
||||
rest-arguments (as in `tt(-foo:*:...)') often allows the use of
|
||||
multiple sets to be avoided.
|
||||
|
||||
To simplify the specifications for commands with standard option
|
||||
parsing, the options tt(-S) and tt(-A) may be given. With tt(-S), no
|
||||
option will be completed after a `tt(-)tt(-)' on the line and this
|
||||
|
@ -3213,13 +3227,6 @@ completing options after the first normal argument, but ignoring all
|
|||
strings starting with a hyphen even if they are not described by one
|
||||
of the var(optspec)s, one would use: `tt(-A "-*")'.
|
||||
|
||||
Note that using multiple sets will be slower than using only one set
|
||||
because the completion code has to parse the command line once for
|
||||
every set. So more than one set should only be used if the command
|
||||
syntax is too complicated. Note also that an option specification with
|
||||
rest-arguments (as in `tt(-foo:*:...)') often allows the use of
|
||||
multiple sets to be avoided.
|
||||
|
||||
Another option supported is `tt(-O) var(name)'. The var(name) will be
|
||||
taken as the name of an array and its elements will be given to
|
||||
functions called to generate matches when executing the
|
||||
|
|
Loading…
Reference in a new issue