1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-11-25 14:20:53 +01:00

add -g option to _parameters to restrict type of parameters completed (12583)

This commit is contained in:
Oliver Kiddle 2000-08-10 21:22:25 +00:00
parent 5b04efd73c
commit 5851a32681
6 changed files with 32 additions and 12 deletions

View file

@ -2,4 +2,4 @@
local expl
_wanted arrays expl array compadd -k "parameters[(R)*array*~*local*]"
_wanted arrays expl array _parameters "$@" -g '*array*'

View file

@ -1,8 +1,9 @@
#compdef getopts unset vared
# This will handle completion of keys of associative arrays, e.g. at
# `vared foo[<TAB>'. However, in this version the [ must be added
# by hand.
# `vared foo[<TAB>'.
local ret=1
if [[ $PREFIX = *\[* ]]; then
local var=${PREFIX%%\[*}
@ -11,7 +12,7 @@ if [[ $PREFIX = *\[* ]]; then
compset -p $(( ${#var} + 1 ))
if ! compset -S \]; then
addclose=(-S ']')
addclose=(-S "${${QIPREFIX:+]}:-\]}")
fi
if [[ ${(tP)var} = assoc* ]]; then
local expl
@ -20,5 +21,13 @@ if [[ $PREFIX = *\[* ]]; then
compadd $addclose -k "$var"
fi
else
_parameters "$@"
_parameters -g '^a*' "$@" && ret=0
if compset -S '\[*'; then
set - -S "" "$@"
else
set - -qS"${${QIPREFIX:+[}:-\[}" "$@"
fi
_parameters -g 'a*' "$@" && ret=0
return ret
fi

View file

@ -10,7 +10,7 @@ _arguments -C -s \
'(-r -w -L -e -b)-d[delete command]:*:name:->name' \
'(-r -L -e -b -d)-w[send string to command]:name:->name:*:strings to write' \
'(: -r -w -e -b -d)-L[list defined commands as calls]' \
'(: -w -L -e -b -d)-r[read string from command]:name:->name:param: _parameters:pattern:' \
'(: -w -L -e -b -d)-r[read string from command]:name:->name:param: _vars:pattern:' \
'(-r -w -L -d):zpty command name:' \
'(-r -w -L -d):cmd: _command_names -e' \
'(-r -w -L -d)*::args:_precommand' && return 0
@ -21,7 +21,7 @@ _arguments -C -s \
# - read \
# '-r[read string from command]' \
# ':name:->name' \
# ':param: _parameters' \
# ':param: _vars' \
# ':pattern:' \
# - write \
# '-w[send string to command]' \

View file

@ -34,7 +34,7 @@ case $key in
'!') _main_complete _command_names
;;
'$') _main_complete - parameters _wanted parameters expl 'exported parameters' \
compadd -k 'parameters[(R)*export*]'
_parameters -g '*export*'
;;
'@') _main_complete _hosts
;;

View file

@ -3,6 +3,13 @@
# This should be used to complete parameter names if you need some of the
# extra options of compadd. It completes only non-local parameters.
local expl
# If you specify a -g option with a pattern, the pattern will be used to
# restrict the type of parameters matched.
_wanted parameters expl parameter compadd "$@" -k 'parameters[(R)^*local*]'
local expl pattern
pattern=(-g \*)
zparseopts -D -K -E g:=pattern
_wanted parameters expl parameter compadd "$@" \
-k "parameters[(R)${pattern[2]}~*local*]"

View file

@ -3470,8 +3470,12 @@ completion functions are called even if there are no matches so far.
)
findex(_parameters)
item(tt(_parameters))(
This should be used to complete parameter names. All arguments are
passed unchanged to the tt(compadd) builtin.
This should be used to complete parameter names. tt(_parameters) can
take a tt(-g var(pattern)) option which specifies that only parameters
whose type matches the var(pattern) should be completed. Strings of
the same form as those returned by the tt(t) parameter expansion flag
are used here when matching the type. All other arguments are passed
unchanged to the tt(compadd) builtin.
)
findex(_path_files)
item(tt(_path_files))(