1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-22 16:20:23 +02:00
zsh/Completion/Base/_describe
1999-10-26 15:36:10 +00:00

73 lines
1.7 KiB
Text

#autoload
# This can be used to add options or values with descriptions as matches.
local isopt cmd opt expl tmps tmpd tmpmd tmpms ret=1 showd _nm hide
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 matches 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
_description expl "$1"
shift
if [[ -n "$showd" ]]; then
compdescribe -I ' -- ' "$@"
else
compdescribe -i "$@"
fi
[[ -n "$isopt" && "$compconfig[option_prefix]" = hide* ]] && hide=yes
while compdescribe -g args tmpd tmpmd tmps tmpms; do
# See if we should remove the option prefix characters.
if [[ -n "$hide" ]]; then
if [[ "$PREFIX" = --* ]]; then
tmpd=( "${(@)tmpd#--}" )
tmps=( "${(@)tmps#--}" )
elif [[ "$PREFIX" = [-+]* ]]; then
tmpd=( "${(@)tmpd#[-+]}" )
tmps=( "${(@)tmps#[-+]}" )
fi
fi
compadd "$args[@]" "$expl[@]" -ld tmpd - "$tmpmd[@]" && ret=0
compadd "$args[@]" "$expl[@]" -d tmps - "$tmpms[@]" && ret=0
done
return ret