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

[PATCH 3/5] bashcompinit: fix quoting code



There's a mismatch between to zsh and bash's quoting:

---
if [[ -n ${ZSH_VERSION-} ]]; then
   autoload -U +X bashcompinit && bashcompinit
fi

_foo()
{
   local cur="${COMP_WORDS[COMP_CWORD]}"
   local IFS=$'\n'
   w[0]='first '
   w[1]='second and space '
   w[2]='third\\ quoted\\ space '
   COMPREPLY=( $(compgen -W "${w[*]}" -- $cur) )
}
complete -o nospace -F _foo foo
---

The result in bash (by typing 'foo f<tab>', 'foo s<tab>', and so on) is:

 'foo first '
 'foo second and space '
 'foo third\ quoted\ space '

In zsh, the results are quite different:

 'foo first\ '
 'foo second\ and\ space\ '
 'foo third\ quoted\ space\ '

The following patch fixes that.

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

diff --git a/Completion/bashcompinit b/Completion/bashcompinit
index 2d6743e..4b2084a 100644
--- a/Completion/bashcompinit
+++ b/Completion/bashcompinit
@@ -24,9 +24,9 @@ _bash_complete() {
     if [[ ${argv[${argv[(I)filenames]:-0}-1]} = -o ]]; then
       compset -P '*/' && matches=( ${matches##*/} )
       compset -S '/*' && matches=( ${matches%%/*} )
-      compadd -f "${suf[@]}" -a matches && ret=0
+      compadd -Q -f "${suf[@]}" -a matches && ret=0
     else
-      compadd "${suf[@]}" -a matches && ret=0
+      compadd -Q "${suf[@]}" -a matches && ret=0
     fi
   fi
 
@@ -135,7 +135,7 @@ compgen() {
         results+=( ${~OPTARG} )
 	unsetopt nullglob
       ;;
-      W) results+=( ${~=OPTARG} ) ;;
+      W) results+=( ${(Q)~=OPTARG} ) ;;
       C) results+=( $(eval $OPTARG) ) ;;
       P) prefix="$OPTARG" ;;
       S) suffix="$OPTARG" ;;
@@ -154,7 +154,7 @@ compgen() {
   #shift $(( OPTIND - 1 ))
   #(( $# )) && results=( "${(M)results[@]:#$1*}" )
 
-  print -l -- "$prefix${^results[@]}$suffix"
+  print -l -r -- "$prefix${^results[@]}$suffix"
 }
 
 complete() {
-- 
1.7.8.3



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