about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2011-05-04 08:53:53 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2011-05-04 08:53:53 +0000
commit2e25dfb8fd38dbef0a306282ffab1d343ce3ad8d (patch)
treea878e23f4ce106b82449d6515d9f5e220f76fe31
parent3355155e825504462167731696345093cae3697e (diff)
downloadzsh-2e25dfb8fd38dbef0a306282ffab1d343ce3ad8d.tar.gz
zsh-2e25dfb8fd38dbef0a306282ffab1d343ce3ad8d.tar.xz
zsh-2e25dfb8fd38dbef0a306282ffab1d343ce3ad8d.zip
Rocky Bernstein: 29135 (plus tweaks): compgen -W in bash completion
-rw-r--r--ChangeLog6
-rw-r--r--Completion/bashcompinit21
-rw-r--r--Test/.distfiles1
-rw-r--r--Test/Y04compgen.ztst21
-rw-r--r--Test/compgentest15
5 files changed, 56 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 9107e0e7d..758a0cc66 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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 $
 *****************************************************
diff --git a/Completion/bashcompinit b/Completion/bashcompinit
index cba436a55..2ccc94de9 100644
--- a/Completion/bashcompinit
+++ b/Completion/bashcompinit
@@ -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" ;;
diff --git a/Test/.distfiles b/Test/.distfiles
index 0e691743b..6a2d1bc4c 100644
--- a/Test/.distfiles
+++ b/Test/.distfiles
@@ -42,6 +42,7 @@ V06parameter.ztst
 Y01completion.ztst
 Y02compmatch.ztst
 Y03arguments.ztst
+Y04compgen.ztst
 comptest
 runtests.zsh
 ztst.zsh
diff --git a/Test/Y04compgen.ztst b/Test/Y04compgen.ztst
new file mode 100644
index 000000000..90dce6148
--- /dev/null
+++ b/Test/Y04compgen.ztst
@@ -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
diff --git a/Test/compgentest b/Test/compgentest
new file mode 100644
index 000000000..26b202c43
--- /dev/null
+++ b/Test/compgentest
@@ -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
+}
+