zsh-workers
 help / color / mirror / code / Atom feed
From: Oliver Kiddle <opk@zsh.org>
To: Zsh hackers list <zsh-workers@zsh.org>
Cc: Felipe Contreras <felipe.contreras@gmail.com>
Subject: PATCH: bashcompinit quoting (was Re: Bug in completion with curly braces?)
Date: Thu, 02 Dec 2021 20:45:16 +0100	[thread overview]
Message-ID: <66838-1638474316.539731@g_Nn.BL1d.lQYb> (raw)
In-Reply-To: <CAMP44s2d5+yHtdCvGDW92vfcbpV=Wn3+-yG74EdST-dJXFZn2A@mail.gmail.com>

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
 


      reply	other threads:[~2021-12-02 19:45 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-20  1:50 Bug in completion with curly braces? Felipe Contreras
2020-11-20  2:52 ` Mikael Magnusson
2020-11-21 15:28 ` Daniel Shahaf
2020-11-21 21:08   ` Felipe Contreras
2020-11-21 22:32     ` Bart Schaefer
2020-11-22  0:37       ` Felipe Contreras
2020-11-22  2:28         ` Bart Schaefer
2020-11-22  2:58           ` Felipe Contreras
2020-11-22 20:35             ` Bart Schaefer
2020-11-22 21:20               ` Bart Schaefer
2020-11-23  3:03               ` Daniel Shahaf
2020-11-23  7:15                 ` Bart Schaefer
2020-11-23  6:46               ` Felipe Contreras
2020-11-23  7:17                 ` Bart Schaefer
2021-04-18 21:43                   ` Bart Schaefer
2020-11-23 17:31                 ` Bart Schaefer
2020-11-24 23:21                   ` Oliver Kiddle
2020-11-25  5:06                     ` Felipe Contreras
2021-12-02 19:45                       ` Oliver Kiddle [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=66838-1638474316.539731@g_Nn.BL1d.lQYb \
    --to=opk@zsh.org \
    --cc=felipe.contreras@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).