mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-12-05 05:21:17 +01:00
Rocky Bernstein: 29135 (plus tweaks): compgen -W in bash completion
This commit is contained in:
parent
3355155e82
commit
2e25dfb8fd
5 changed files with 56 additions and 8 deletions
|
|
@ -1,5 +1,9 @@
|
|||
2011-05-04 Peter Stephenson <pws@csr.com>
|
||||
|
||||
* Rocky Bernstein: 29135 (plus tweaks): Completion/bashcompinit,
|
||||
Test/.distfiles, Test/Y04compgen.ztst, Test/compgentest: fix and
|
||||
test "compgen -W" in bash completion.
|
||||
|
||||
* unposted: NEWS: a few notes for next release.
|
||||
|
||||
2011-05-03 Peter Stephenson <p.w.stephenson@ntlworld.com>
|
||||
|
|
@ -14574,5 +14578,5 @@
|
|||
|
||||
*****************************************************
|
||||
* This is used by the shell to define $ZSH_PATCHLEVEL
|
||||
* $Revision: 1.5275 $
|
||||
* $Revision: 1.5276 $
|
||||
*****************************************************
|
||||
|
|
|
|||
|
|
@ -12,14 +12,14 @@ _bash_complete() {
|
|||
(( COMP_CWORD = CURRENT - 1))
|
||||
COMP_WORDS=( $words )
|
||||
BASH_VERSINFO=( 2 05b 0 1 release )
|
||||
|
||||
|
||||
savejobstates=( ${(kv)jobstates} )
|
||||
savejobtexts=( ${(kv)jobtexts} )
|
||||
|
||||
|
||||
[[ ${argv[${argv[(I)nospace]:-0}-1]} = -o ]] && suf=( -S '' )
|
||||
|
||||
|
||||
matches=( ${(f)"$(compgen $@)"} )
|
||||
|
||||
|
||||
if [[ -n $matches ]]; then
|
||||
if [[ ${argv[${argv[(I)filenames]:-0}-1]} = -o ]]; then
|
||||
compset -P '*/' && matches=( ${matches##*/} )
|
||||
|
|
@ -41,11 +41,18 @@ _bash_complete() {
|
|||
return ret
|
||||
}
|
||||
|
||||
_compgen_opt_words() {
|
||||
typeset -a words
|
||||
words=( ${~=1} )
|
||||
local find="$2"
|
||||
results=(${(M)words[@]:#$find*})
|
||||
}
|
||||
|
||||
compgen() {
|
||||
local opts prefix suffix job OPTARG OPTIND ret=1
|
||||
local opts prefix suffix job OPTARG OPTIND ret=1
|
||||
local -a name res results jids
|
||||
local -A shortopts
|
||||
|
||||
|
||||
emulate -L sh
|
||||
setopt kshglob noshglob braceexpand nokshautoload
|
||||
|
||||
|
|
@ -128,7 +135,7 @@ compgen() {
|
|||
results+=( ${~OPTARG} )
|
||||
unsetopt nullglob
|
||||
;;
|
||||
W) eval "results+=( $OPTARG )" ;;
|
||||
W) _compgen_opt_words "$OPTARG" "${@[-1]}" ;;
|
||||
C) results+=( $(eval $OPTARG) ) ;;
|
||||
P) prefix="$OPTARG" ;;
|
||||
S) suffix="$OPTARG" ;;
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ V06parameter.ztst
|
|||
Y01completion.ztst
|
||||
Y02compmatch.ztst
|
||||
Y03arguments.ztst
|
||||
Y04compgen.ztst
|
||||
comptest
|
||||
runtests.zsh
|
||||
ztst.zsh
|
||||
|
|
|
|||
21
Test/Y04compgen.ztst
Normal file
21
Test/Y04compgen.ztst
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# Tests for bash compgen compatibility.
|
||||
|
||||
%prep
|
||||
if ( zmodload zsh/parameter ) >/dev/null 2>&1; then
|
||||
. $ZTST_srcdir/compgentest
|
||||
comptestinit -z $ZTST_testdir/../Src/zsh &&
|
||||
else
|
||||
ZTST_unimplemented="the zsh/parameter module is not available"
|
||||
fi
|
||||
|
||||
%test
|
||||
|
||||
comptest $': \t\t\t\t\t\t\t'
|
||||
0:bash compatibility: compgen -W
|
||||
>abc
|
||||
>abe
|
||||
>ab
|
||||
|
||||
%clean
|
||||
|
||||
zmodload -ui zsh/parameter
|
||||
15
Test/compgentest
Normal file
15
Test/compgentest
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
comptestinit () {
|
||||
|
||||
setopt extendedglob
|
||||
[[ -d $ZTST_testdir/Modules/zsh ]] && module_path=( $ZTST_testdir/Modules )
|
||||
|
||||
zmodload -i zsh/parameter || return $?
|
||||
autoload -Uz bashcompinit || return $?
|
||||
bashcompinit || return $?
|
||||
|
||||
}
|
||||
|
||||
comptest () {
|
||||
compgen -W 'abc abe ab a def' ab
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue