Re: possible bug in autocompletion

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Sep 19, 2012 at 8:16 PM, Felipe Contreras
<felipe.contreras@xxxxxxxxx> wrote:
> On Wed, Sep 19, 2012 at 7:43 PM, Jeff King <peff@xxxxxxxx> 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@xxxxxxxx> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]