From: Jeff King <peff@peff.net>
To: Felipe Contreras <felipe.contreras@gmail.com>
Cc: Jeroen Meijer <jjgmeijer@hotmail.com>, git@vger.kernel.org
Subject: Re: possible bug in autocompletion
Date: Wed, 19 Sep 2012 15:55:18 -0400 [thread overview]
Message-ID: <20120919195518.GA22310@sigill.intra.peff.net> (raw)
In-Reply-To: <CAMP44s1ZVTgBTQDyBHKvos-uSo0FeOO437MvTYH0YE0Lx-xDOA@mail.gmail.com>
On Wed, Sep 19, 2012 at 08:23:01PM +0200, Felipe Contreras wrote:
> >> Care to wrap it up in a patch?
> >
> > I'm trying to, but unfortunately "\n" gets converted to "\\n", so it
> > doesn't get separated to words. Any ideas?
>
> Actually, this seems to do the trick:
>
> local words IFS=$'\n'
> printf -v words "%q" "$1"
> COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "${words//\\n/$IFS}"
> -- "${3-$cur}"))
>
> I don't know how to do $'\n' in the middle of double-quotes, but $IFS works.
I don't think you can search-and-replace backslash-escaped characters
and always get the correct result. For example, in this string:
\\n
Your regex would match the "\n", missing the context that the backslash
is actually the second-half of an escaped pair. Searching for "[^\\]\\n"
would similarly miss that:
\\\n
should be converted. IOW, I think backslash-escaping fundamentally has
to either be parsed left-to-right, or quoted backslashes peeled in order
(if I were not such a bad computer scientist, I could probably come up
with some proof involving Chomsky's hierarchy of grammars).
I think the real problem is that we are feeding "printf %q" an input
where we want _most_ of the constructs quoted, but not some (namely
newline, which is syntactically significant, and which we accept will
break our completion). So something like the manual quoting I posted
earlier in the thread is actually much closer to what we want.
On a related note, I notice that even with either of our patches, doing
this:
echo content >'${foo.bar}'
git add .
git commit -m whatever
git show HEAD:<tab>
will yield this completion:
git show HEAD:${foo.bar}
which is correct, but not useful. It needs to be quoted _again_ to avoid
interpolation when you actually quote the command. Bash's filename
completion handles this automatically. E.g., if you do:
git add <tab>
you will get:
git add \$\{foo.bar\}
I have no idea if that internal to bash's filename completion, or if
there is some easy facility offered to programmable completions to do
the same thing. I don't think this is a high priority, but it would be
nice to handle it. And moreover, I am really wondering if we are missing
some solution that bash is providing to help us with the quoting issues.
Surely we are not the first completion script to come up against this.
-Peff
next prev parent reply other threads:[~2012-09-19 19:55 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-17 9:10 possible bug in autocompletion Jeroen Meijer
2012-07-17 12:12 ` Jeff King
2012-09-19 17:08 ` Felipe Contreras
2012-09-19 17:43 ` Jeff King
2012-09-19 18:16 ` Felipe Contreras
2012-09-19 18:23 ` Felipe Contreras
2012-09-19 19:55 ` Jeff King [this message]
2012-09-19 23:08 ` Felipe Contreras
2012-09-19 23:43 ` Jeff King
2012-09-19 17:58 ` Junio C Hamano
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=20120919195518.GA22310@sigill.intra.peff.net \
--to=peff@peff.net \
--cc=felipe.contreras@gmail.com \
--cc=git@vger.kernel.org \
--cc=jjgmeijer@hotmail.com \
/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.
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).