From 5851a32681f5fbdbc55987cb117f891e3745f13c Mon Sep 17 00:00:00 2001 From: Oliver Kiddle Date: Thu, 10 Aug 2000 21:22:25 +0000 Subject: add -g option to _parameters to restrict type of parameters completed (12583) --- Completion/Builtins/_arrays | 2 +- Completion/Builtins/_vars | 17 +++++++++++++---- Completion/Builtins/_zpty | 4 ++-- Completion/Commands/_bash_completions | 2 +- Completion/Core/_parameters | 11 +++++++++-- Doc/Zsh/compsys.yo | 8 ++++++-- 6 files changed, 32 insertions(+), 12 deletions(-) diff --git a/Completion/Builtins/_arrays b/Completion/Builtins/_arrays index 5ab6d41f0..c28fb179e 100644 --- a/Completion/Builtins/_arrays +++ b/Completion/Builtins/_arrays @@ -2,4 +2,4 @@ local expl -_wanted arrays expl array compadd -k "parameters[(R)*array*~*local*]" +_wanted arrays expl array _parameters "$@" -g '*array*' diff --git a/Completion/Builtins/_vars b/Completion/Builtins/_vars index a46b99de0..501e37b4f 100644 --- a/Completion/Builtins/_vars +++ b/Completion/Builtins/_vars @@ -1,8 +1,9 @@ #compdef getopts unset vared # This will handle completion of keys of associative arrays, e.g. at -# `vared foo['. However, in this version the [ must be added -# by hand. +# `vared foo['. + +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 diff --git a/Completion/Builtins/_zpty b/Completion/Builtins/_zpty index f1de3d11d..b7e355149 100644 --- a/Completion/Builtins/_zpty +++ b/Completion/Builtins/_zpty @@ -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]' \ diff --git a/Completion/Commands/_bash_completions b/Completion/Commands/_bash_completions index 3c19358b7..dd6998971 100644 --- a/Completion/Commands/_bash_completions +++ b/Completion/Commands/_bash_completions @@ -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 ;; diff --git a/Completion/Core/_parameters b/Completion/Core/_parameters index d3a163b49..578bf4428 100644 --- a/Completion/Core/_parameters +++ b/Completion/Core/_parameters @@ -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*]" diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo index 9a0c1a57d..6f378a3de 100644 --- a/Doc/Zsh/compsys.yo +++ b/Doc/Zsh/compsys.yo @@ -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))( -- cgit 1.4.1