mirror of
git://git.code.sf.net/p/zsh/code
synced 2024-11-19 13:33:52 +01:00
99 lines
2.1 KiB
Plaintext
99 lines
2.1 KiB
Plaintext
|
#autoload
|
||
|
|
||
|
local comp pat val name i ret=1 _compskip="$_compskip"
|
||
|
local curcontext="$curcontext" service str comptype noskip def
|
||
|
local __comps __patcomps __postpatcomps __services
|
||
|
|
||
|
# If we get the option `-s', we don't reset `_compskip'.
|
||
|
|
||
|
while [[ "$1" = -[sd] ]]; do
|
||
|
if [[ "$1" = -s ]]; then
|
||
|
noskip=yes
|
||
|
else
|
||
|
def=yes
|
||
|
fi
|
||
|
shift
|
||
|
done
|
||
|
|
||
|
[[ -z "$noskip" ]] && _compskip=
|
||
|
|
||
|
comptype=$1
|
||
|
|
||
|
__comps=_$1
|
||
|
|
||
|
(( ${(P)+__comps} )) || return 1
|
||
|
|
||
|
__patcomps=_pat$1
|
||
|
__postpatcomps=_postpat$1
|
||
|
__services=_service$1
|
||
|
|
||
|
shift
|
||
|
|
||
|
# See if there are any matching pattern completions.
|
||
|
|
||
|
if [[ "$_compskip" != (all|*patterns*) ]]; then
|
||
|
|
||
|
for str in "$@"; do
|
||
|
[[ -n "$str" ]] || continue
|
||
|
service="${${(e):-\$${__services}[\$str]}:-$str}"
|
||
|
for i in "${(@e):-\$${__patcomps}[(K)\$str]}"; do
|
||
|
"$i" && ret=0
|
||
|
if [[ "$_compskip" = *patterns* ]]; then
|
||
|
break
|
||
|
elif [[ "$_compskip" = all ]]; then
|
||
|
_compskip=''
|
||
|
return ret
|
||
|
fi
|
||
|
done
|
||
|
done
|
||
|
fi
|
||
|
|
||
|
# Now look up the names in the normal completion array.
|
||
|
|
||
|
ret=1
|
||
|
for str in "$@"; do
|
||
|
[[ -n "$str" ]] || continue
|
||
|
name="$str"
|
||
|
comp="${(e):-\$${__comps}[\$str]}"
|
||
|
service="${${(e):-\$${__services}[\$str]}:-$str}"
|
||
|
|
||
|
[[ -z "$comp" ]] || break
|
||
|
done
|
||
|
|
||
|
# And generate the matches, probably using default completion.
|
||
|
|
||
|
if [[ -n "$comp" ]]; then
|
||
|
_compskip=patterns
|
||
|
eval "$comp" && ret=0
|
||
|
[[ "$_compskip" = (all|*patterns*) ]] && return ret
|
||
|
elif [[ "$_compskip" != *default* ]]; then
|
||
|
name=-default-
|
||
|
comp="${(e):-\$${__comps}[-default-]}"
|
||
|
fi
|
||
|
|
||
|
if [[ "$_compskip" != (all|*patterns*) ]]; then
|
||
|
for str; do
|
||
|
[[ -n "$str" ]] || continue
|
||
|
service="${${(e):-\$${__services}[\$str]}:-$str}"
|
||
|
for i in "${(@e):-\$${__postpatcomps}[(K)\$str]}"; do
|
||
|
_compskip=default
|
||
|
"$i" && ret=0
|
||
|
if [[ "$_compskip" = *patterns* ]]; then
|
||
|
break
|
||
|
elif [[ "$_compskip" = all ]]; then
|
||
|
_compskip=''
|
||
|
return ret
|
||
|
fi
|
||
|
done
|
||
|
done
|
||
|
fi
|
||
|
|
||
|
[[ "$name" = -default- && -n "$comp" &&
|
||
|
"$_compskip" != (all|*default*) ]] &&
|
||
|
service="${${(e):-\$${__services}[-default-]}:--default-}" &&
|
||
|
eval "$comp" && ret=0
|
||
|
|
||
|
_compskip=''
|
||
|
|
||
|
return ret
|