From: "Daniel Shahaf" <d.s@daniel.shahaf.name>
To: "Felipe Contreras" <felipe.contreras@gmail.com>,
"Zsh hackers list" <zsh-workers@zsh.org>
Subject: Re: Bug in completion with curly braces?
Date: Sat, 21 Nov 2020 15:28:45 +0000 [thread overview]
Message-ID: <69b1ff42-3e60-4b40-8514-9bb0690eb250@www.fastmail.com> (raw)
In-Reply-To: <CAMP44s1suGkR83v82+C8xUUG3J8fwyuwPamujvRUPLcNyQdeJw@mail.gmail.com>
Felipe Contreras wrote on Fri, 20 Nov 2020 01:50 +00:00:
> compadd -Q -- 'stash@{0}' 'stash@{1}'
>
> The first completion correctly generates "stash@{", but the second one
> generates curly braces, the third one does the same, and so on ad
> infinitum.
>
I can reproduce this in «zsh -f» zsh-5.8-259-g00d20ed. I don't get a segfault.
> I didn't specify file (-f) or any special completion, so why would zle
> attempt curly brace expansion, especially if the words contain curly
> braces, and the current character is a curly brace?
Inserting the braces into the command line unescaped is correct since -Q
was passed to compadd. (Note that when -Q is not provided, the braces
_are_ inserted escaped.)
Treating them as starting a brace expansion is also correct, because -Q
doesn't disable that part of the grammar. -Q only means that when a
candidate completion is inserted into the command line, the inserted
word doesn't get escaped (e.g., compare «compadd 'foo$bar'» to «compadd
-Q 'foo$bar'»). If that word contains metacharacters (e.g., «compadd -Q
'|| /bin/echo hello world'»), then -Q makes it the caller's
responsibility to escape them as needed.
Consequently, brace expansion is presumably attempted for the same
reason it s attempted when the words don't contain braces. E.g., after
«compadd -Q bar baz» followed by «foo ba{<TAB>», it offers «r» and «z»
as completions, which let you build up «{bar,baz}» and «{baz,bar}»
respectively. Similarly, given «stash@{<TAB>», it presumably takes the
brace for the start of a brace expansion, and the analogous construct
which that behaviour lets you build up is «stash@{\{0\},\{1\}}» or
«stash@{\{1\},\{0\}}» — except that when you press <TAB> a second time,
the newly-inserted brace is once again inserted unescaped, which
presumably gets handled as the start of a nested brace expansion.
As to -f, curly brace expansion is perfectly valid for arguments that
aren't filenames, such as «compadd -Q stash@\{{0,1}\}». (Brace
expansion is several layers removed from filenameness checks, which is
why stuff like «ls {-{l,d},/bin}» works.)
You can probably just remove the -Q.
Daniel
next prev parent reply other threads:[~2020-11-21 15:29 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-20 1:50 Felipe Contreras
2020-11-20 2:52 ` Mikael Magnusson
2020-11-21 15:28 ` Daniel Shahaf [this message]
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 ` PATCH: bashcompinit quoting (was Re: Bug in completion with curly braces?) Oliver Kiddle
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=69b1ff42-3e60-4b40-8514-9bb0690eb250@www.fastmail.com \
--to=d.s@daniel.shahaf.name \
--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).