git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: possible bug in autocompletion

From
Felipe Contreras <felipe.contreras@gmail.com>
Date
Sep 19, 2012, 18:23 UTC
Message-ID
<CAMP44s1ZVTgBTQDyBHKvos-uSo0FeOO437MvTYH0YE0Lx-xDOA@mail.gmail.com>
In-Reply-To
<CAMP44s1Xvvs7g1quUEs2b43VciK2=Nt-AntJcwG0CPf6p8Xk_A@mail.gmail.com>

On Wed, Sep 19, 2012 at 8:16 PM, Felipe Contreras <felipe.contreras@gmail.com> wrote:

Show 33 quoted lines
> On Wed, Sep 19, 2012 at 7:43 PM, Jeff King <peff@peff.net> wrote:
>> On Wed, Sep 19, 2012 at 07:08:09PM +0200, Felipe Contreras wrote:
>>
>>> On Tue, Jul 17, 2012 at 2:12 PM, Jeff King <peff@peff.net> wrote:
>>>
>>> > --- a/contrib/completion/git-completion.bash
>>> > +++ b/contrib/completion/git-completion.bash
>>> > @@ -261,7 +261,12 @@ __gitcomp ()
>>> >  __gitcomp_nl ()
>>> >  {
>>> >         local IFS=$'\n'
>>> > -       COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$1" -- "${3-$cur}"))
>>> > +       local words=$1
>>> > +       words=${words//\\/\\\\}
>>> > +       words=${words//\$/\\\$}
>>> > +       words=${words//\'/\\\'}
>>> > +       words=${words//\"/\\\"}
>>> > +       COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$words" -- "${3-$cur}"))
>>> >  }
>>>
>>> What about something like this?
>>>
>>> local words
>>> printf -v words "%q" "$w"
>>> COMPREPLY=($(compgen -P "${2-}" -S "${4- }" -W "$words" -- "${3-$cur}"))
>>
>> Thanks, I didn't know about bash's internal printf magic. That is a much
>> more elegant solution.
>>
>> 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.
-- 
Felipe Contreras
Previous: Felipe ContrerasNext: Jeff King
Message 6 of 10 in “possible bug in autocompletion”
  1. Jeroen MeijerJul 17, 2012
  2. Jeff KingJul 17, 2012
  3. Felipe ContrerasSep 19, 2012
  4. Jeff KingSep 19, 2012
  5. Felipe ContrerasSep 19, 2012
  6. Felipe ContrerasSep 19, 2012
  7. Jeff KingSep 19, 2012
  8. Felipe ContrerasSep 19, 2012
  9. Jeff KingSep 19, 2012
  10. Junio C HamanoSep 19, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.