1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-01-21 12:11:26 +01:00
zsh/Completion/Base/Utility/_pick_variant
Bart Schaefer 027ce9a001 26609: _path_files: better (?) fix for globcomplete.
unposted: _pick_variant: explicit rather than implicit success return.
2009-02-28 07:11:31 +00:00

35 lines
737 B
Text

#autoload
local output cmd pat
local -a var
local -A opts
(( $+_cmd_variant )) || typeset -gA _cmd_variant
zparseopts -D -A opts c: r:
: ${opts[-c]:=$words[1]}
while [[ $1 = *=* ]]; do
var+=( "${1%%\=*}" "${1#*=}" )
shift
done
if (( $+_cmd_variant[$opts[-c]] )); then
(( $+opts[-r] )) && eval "${opts[-r]}=${_cmd_variant[$opts[-c]]}"
[[ $_cmd_variant[$opts[-c]] = "$1" ]] && return 1
return 0
fi
output="$(_call_program variant $opts[-c] "${@[2,-1]}" </dev/null 2>&1)"
for cmd pat in "$var[@]"; do
if [[ $output = *$~pat* ]]; then
(( $+opts[-r] )) && eval "${opts[-r]}=$cmd"
_cmd_variant[$opts[-c]]="$cmd"
return 0
fi
done
(( $+opts[-r] )) && eval "${opts[-r]}=$1"
_cmd_variant[$opts[-c]]="$1"
return 1