Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH 5/5] bashcompinit: improve compgen -F argument passing



Otherwise something like

 % compgen -F _foo -- fi

Would not pass the arguments ('fi') to the function, like bash does.

I looked that the source code of bash, and they pass only the first
extra argument as argv $2. Let's do the same.

This is not a big deal, as 'compgen -F' would match the results, instead
of 'compgen -W' like in bash, but the end result is the same. Same as if
zsh's matching (compadd) is used instead.

Signed-off-by: Felipe Contreras <felipe.contreras@xxxxxxxxx>
---
 Completion/bashcompinit |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/Completion/bashcompinit b/Completion/bashcompinit
index 9c561c5..31f64f8 100644
--- a/Completion/bashcompinit
+++ b/Completion/bashcompinit
@@ -18,7 +18,7 @@ _bash_complete() {
 
   [[ ${argv[${argv[(I)nospace]:-0}-1]} = -o ]] && suf=( -S '' )
 
-  matches=( ${(f)"$(compgen $@)"} )
+  matches=( ${(f)"$(compgen $@ ${words[CURRENT]})"} )
 
   if [[ -n $matches ]]; then
     if [[ ${argv[${argv[(I)filenames]:-0}-1]} = -o ]]; then
@@ -121,12 +121,13 @@ compgen() {
       ;;
       F)
         COMPREPLY=()
+        local -a args
+        args=( "${words[0]}" "${@[-1]}" "${words[CURRENT-2]}" )
         (){
-          set -- "${words[0]}" "${words[CURRENT-1]}" "${words[CURRENT-2]}"
           # There may be more things we need to add to this typeset to
           # protect bash functions from compsys special variable names
           typeset -h words
-          $OPTARG "$@"
+          $OPTARG "${args[@]}"
         }
 	results+=( "${COMPREPLY[@]}" )
       ;;
-- 
1.7.8.3



Messages sorted by: Reverse Date, Date, Thread, Author