summaryrefslogtreecommitdiff
path: root/Completion/Base
diff options
context:
space:
mode:
Diffstat (limited to 'Completion/Base')
-rw-r--r--Completion/Base/_argument_sets86
-rw-r--r--Completion/Base/_arguments70
2 files changed, 25 insertions, 131 deletions
diff --git a/Completion/Base/_argument_sets b/Completion/Base/_argument_sets
deleted file mode 100644
index f8a55dad9..000000000
--- a/Completion/Base/_argument_sets
+++ /dev/null
@@ -1,86 +0,0 @@
-#autoload
-
-local all ret=1 end xor has_args had_args ostate ocontext oopt_args r
-local nm="$compstate[nmatches]"
-local opre="$PREFIX" oipre="$IPREFIX" ocur="$CURRENT"
-local osuf="$SUFFIX" oisuf="$ISUFFIX" owords
-local _ms_match _ms_opt _ms_soptmid _ms_soptmidadd _ms_soptend
-local _ms_optnext _ms_optdirect _ms_optequal
-
-_ms_soptmid=()
-_ms_soptmidadd=()
-_ms_soptend=()
-_ms_optnext=()
-_ms_optdirect=()
-_ms_optequal=()
-
-owords=("$words[@]")
-
-end=$argv[(i)-]
-[[ end -gt $# ]] && return 1
-
-all=( "${(@)argv[1,end]}" )
-
-shift end
-
-xor=()
-ostate=()
-ocontext=()
-oopt_args=()
-
-while true; do
- end=$argv[(i)-]
-
- if [[ "$1" = \(*\) ]]; then
- _arguments -m xor "${1[2,-2]}" "$all[@]" \
- "$1${(@)^argv[2,end-1]:#\(*}" \
- "${1[1,-2]} ${(@)${(@M)^argv[2,end-1]:#\(*}#?}"
- else
- _arguments -m xor "$1" "$all[@]" "${(@)argv[2,end-1]}"
- fi
-
- r=$?
-
- oopt_args=( "$oopt_args[@]" "${(@kv)opt_args}" )
- if [[ r -eq 300 ]]; then
- ret=300
- ostate=( "$ostate[@]" "$state[@]" )
- ocontext=( "$ocontext[@]" "$context[@]" )
- PREFIX="$opre" SUFFIX="$osuf"
- IPREFIX="$oipre" ISUFFIX="$oisuf"
- CURRENT="$ocur" words=( "$owords[@]" )
- elif [[ "$r$ret" = 01 ]]; then
- ret=0
- fi
-
- [[ end -gt $# ]] && break
-
- shift end
-done
-
-[[ -n "$_ms_opt" ]] &&
- { ! zstyle -T ":completion:${curcontext}:options" prefix-needed ||
- [[ "$PREFIX" = [-+]* ||
- ( -z "$has_args" && ret -ne 300 && nm -eq compstate[nmatches] ) ]] } &&
- has_args=yes &&
- _describe -o option \
- _ms_soptmid _ms_soptmidadd -Q -S '' -- \
- _ms_soptend -Q -- \
- _ms_optnext -Q -M "$_ms_match" -- \
- _ms_optdirect -QS '' -M "$_ms_match" -- \
- _ms_optequal -QqS= -M "$_ms_match" && [[ ret -eq 1 ]] && ret=0
-
-opt_args=( "$oopt_args[@]" )
-
-if [[ ret -eq 300 ]]; then
- state=( "$ostate[@]" )
- context=( "$ocontext[@]" )
-elif [[ -z "$has_args" ]]; then
- if [[ -n "$had_args" ]]; then
- _message "no more arguments"
- else
- _message "no arguments"
- fi
-fi
-
-return ret
diff --git a/Completion/Base/_arguments b/Completion/Base/_arguments
index f819f69c9..1fcf34a10 100644
--- a/Completion/Base/_arguments
+++ b/Completion/Base/_arguments
@@ -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 multi ismulti
+local oldcontext="$curcontext" hasopts
long=$argv[(I)--]
if (( long )); then
@@ -23,7 +23,7 @@ if (( long )); then
name="${name//[^a-zA-Z0-9_]/_}"
if (( ! ${(P)+name} )); then
- local iopts sopts pattern tmpo cur cache
+ local iopts sopts pattern tmpo dir cur cache
typeset -U lopts
cache=()
@@ -98,6 +98,12 @@ if (( long )); then
pattern="${${${(M)1#*[^\\]:}[1,-2]}//\\\\:/:}"
descr="${1#${pattern}}"
+ if [[ "$pattern" = *\(-\) ]]; then
+ pattern="$pattern[1,-4]"
+ dir=-
+ else
+ dir=
+ fi
shift
# We get all options matching the pattern and take them from the
@@ -111,7 +117,7 @@ if (( long )); then
opt=''
- # If there are option strings with a `[=', we take these get an
+ # If there are option strings with a `[=', we take these to get an
# optional argument.
tmpo=("${(@M)tmp:#*\[\=*}")
@@ -120,9 +126,9 @@ if (( long )); then
tmpo=("${(@)${(@)tmpo%%\=*}//[^a-z0-9-]}")
if [[ "$descr" = ::* ]]; then
- cache=( "$cache[@]" "${(@)^tmpo}=${descr}" )
+ cache=( "$cache[@]" "${(@)^tmpo}=${dir}${descr}" )
else
- cache=( "$cache[@]" "${(@)^tmpo}=:${descr}" )
+ cache=( "$cache[@]" "${(@)^tmpo}=${dir}:${descr}" )
fi
fi
@@ -133,10 +139,10 @@ if (( long )); then
tmp=("${(@)tmp:#*\=*}")
tmpo=("${(@)${(@)tmpo%%\=*}//[^a-z0-9-]}")
- cache=( "$cache[@]" "${(@)^tmpo}=${descr}" )
+ cache=( "$cache[@]" "${(@)^tmpo}=${dir}${descr}" )
fi
- # Everything else is just added as a option without arguments.
+ # Everything else is just added as an option without arguments.
if (( $#tmp )); then
tmp=("${(@)tmp//[^a-zA-Z0-9-]}")
@@ -148,27 +154,22 @@ if (( long )); then
set -- "$tmpargv[@]" "${(@P)name}"
fi
-multi=(-i)
subopts=()
while [[ "$1" = -(O*|C|m*) ]]; do
case "$1" in
-C) usecc=yes; shift ;;
-O) subopts=( "${(@P)2}" ); shift 2 ;;
-O*) subopts=( "${(@P)1[3,-1]}" ); shift ;;
- -m) ismulti=yes multi=(-I "$2" "$3"); shift 3 ;;
- -m*) ismulti=yes multi=(-I "${1[3,-1]}" "$2"); shift 2 ;;
esac
done
zstyle -s ":completion:${curcontext}:options" auto-description autod
-if (( $# )) && comparguments "$multi[@]" "$autod" "$@"; then
+if (( $# )) && comparguments -i "$autod" "$@"; 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
- local origpre="$PREFIX" origipre="$IPREFIX"
-
- [[ -z "$ismulti" ]] && local nm="$compstate[nmatches]"
+ local origpre="$PREFIX" origipre="$IPREFIX" nm="$compstate[nmatches]"
if comparguments -D descrs actions subcs; then
if comparguments -O next direct odirect equal; then
@@ -180,7 +181,6 @@ if (( $# )) && comparguments "$multi[@]" "$autod" "$@"; then
else
if comparguments -a; then
noargs='no more arguments'
- had_args=yes
else
noargs='no arguments'
fi
@@ -299,8 +299,7 @@ if (( $# )) && comparguments "$multi[@]" "$autod" "$@"; then
done
if [[ -z "$matched$hasopts" ]] && _requested options &&
- { [[ -n "$ismulti" ]] ||
- ! zstyle -T ":completion:${curcontext}:options" prefix-needed ||
+ { ! zstyle -T ":completion:${curcontext}:options" prefix-needed ||
[[ "$origpre" = [-+]* || -z "$aret$mesg$tried" ]] } ; then
local prevpre="$PREFIX" previpre="$IPREFIX"
@@ -326,37 +325,22 @@ if (( $# )) && comparguments "$multi[@]" "$autod" "$@"; then
tmp1=( "${(M@)tmp1:#[-+]?(|:*)}" )
tmp2=( "${PREFIX}${(@M)^${(@)${(@)tmp1%%:*}#[-+]}:#?}" )
- if [[ -n "$ismulti" ]]; then
- _ms_opt=yes
- _ms_soptmid=( "$_ms_soptmid[@]" "$tmp1[@]" )
- _ms_soptmidadd=( "$_ms_soptmidadd[@]" "$tmp2[@]" )
- _ms_soptend=( "$_ms_soptend[@]" "$tmp3[@]" )
- else
- _describe -o option \
- tmp1 tmp2 -Q -S '' -- \
- tmp3 -Q
- fi
+ _describe -o option \
+ tmp1 tmp2 -Q -S '' -- \
+ tmp3 -Q
fi
single=yes
else
next=( "$next[@]" "$odirect[@]" )
- if [[ -n "$ismulti" ]]; then
- _ms_opt=yes
- _ms_match="$_ms_match $matcher"
- _ms_optnext=( "$_ms_optnext[@]" "$next[@]" )
- _ms_optdirect=( "$_ms_optdirect[@]" "$direct[@]" )
- _ms_optequal=( "$_ms_optequal[@]" "$equal[@]" )
- else
- _describe -o option \
- next -Q -M "$matcher" -- \
- direct -QS '' -M "$matcher" -- \
- equal -QqS= -M "$matcher"
- fi
+ _describe -o option \
+ next -Q -M "$matcher" -- \
+ direct -QS '' -M "$matcher" -- \
+ equal -QqS= -M "$matcher"
fi
PREFIX="$prevpre"
IPREFIX="$previpre"
fi
- [[ -n "$tried" ]] && break
+ [[ -n "$tried" && "$PREFIX" != [-+]* ]] && break
done
if [[ -n "$opts" && -z "$aret$matched$mesg" &&
nm -eq compstate[nmatches] ]]; then
@@ -391,11 +375,7 @@ if (( $# )) && comparguments "$multi[@]" "$autod" "$@"; then
[[ -n "$aret" ]] && return 300
- if [[ -n "$noargs" ]]; then
- [[ -z "$ismulti" && nm -eq "$compstate[nmatches]" ]] && _message "$noargs"
- else
- has_args=yes
- fi
+ [[ -n "$noargs" && nm -eq "$compstate[nmatches]" ]] && _message "$noargs"
# Set the return value.