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

PATCH: bashcompinit quoting (was Re: Bug in completion with curly braces?)



On 24 Nov 2020, Felipe Contreras wrote:
> > We could do something like the following in bashcompinit to special case
> > only space suffixes:
> >
> > -      compadd -Q "${suf[@]}" -a matches && ret=0
> > +      compadd "${suf[@]}" - "${(@)${(Q@)matches}:#*\ }" && ret=0
> > +      compadd -S ' ' - ${${(M)${(Q)matches}:#*\ }% } && ret=0
>
> Yes, that should work. Although I think bash would add two spaces if
> -o nospace isn't specified.

I never did anything further with this a year ago. Revisiting it
and trying to find examples, that approach does seem to be more
compatible with bash.

bashcompinit did acquire two uses of -Q. The other case is for
filename completion. The bash complete builtin has at some point
acquired a noquote option which will "Tell readline not to quote
the completed words if they are filenames (quoting filenames is the
default)." So I think the right change in that position is merely
to remove the -Q. The patch does this.

Bash has a few newer complete options and a new compopt builtin
for changing the applicable options from within a bash completion
function. It doesn't look especially hard to implement these but
I'm not sure how wise that is. bashcompinit was possibly a mistake
to begin with. If people are using it then supporting newer features
would improve their experience. And maybe give them less motivation
to write a native zsh function.

Oliver

diff --git a/Completion/bashcompinit b/Completion/bashcompinit
index b278ac8f4..adb659ca1 100644
--- a/Completion/bashcompinit
+++ b/Completion/bashcompinit
@@ -24,9 +24,10 @@ _bash_complete() {
     if [[ ${argv[${argv[(I)filenames]:-0}-1]} = -o ]]; then
       compset -P '*/' && matches=( ${matches##*/} )
       compset -S '/*' && matches=( ${matches%%/*} )
-      compadd -Q -f "${suf[@]}" -a matches && ret=0
+      compadd -f "${suf[@]}" -a matches && ret=0
     else
-      compadd -Q "${suf[@]}" -a matches && ret=0
+      compadd "${suf[@]}" - "${(@)${(Q@)matches}:#*\ }" && ret=0
+      compadd -S ' ' - ${${(M)${(Q)matches}:#*\ }% } && ret=0
     fi
   fi
 




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