git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [QUERY] How do you sort completions?
@ 2013-05-24 11:33 Ramkumar Ramachandra
  2013-05-24 13:11 ` Felipe Contreras
  2013-05-24 16:12 ` SZEDER Gábor
  0 siblings, 2 replies; 8+ messages in thread
From: Ramkumar Ramachandra @ 2013-05-24 11:33 UTC (permalink / raw)
  To: Git List; +Cc: SZEDER Gábor, Felipe Contreras

Hi,

I'm not able to sort completions for some weird reason.  No matter
what I order I insert stuff into COMPREPLY, bash seems to auto-sort
them lexically.  I tried to pass --sort='-committerdate' to git
for-each-ref so I can get a sensible 'git checkout <TAB>' reply, and
I'm very annoyed that it doesn't work.

I thought it was bash's complete builtin doing the implicit sorting,
so I read the manual with no success.  Is readline doing it?  If so,
why am I not getting the ordering even in zsh (which doesn't use
readline)?

What am I missing?

Ram

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [QUERY] How do you sort completions?
  2013-05-24 11:33 [QUERY] How do you sort completions? Ramkumar Ramachandra
@ 2013-05-24 13:11 ` Felipe Contreras
  2013-05-28 10:23   ` SZEDER Gábor
  2013-05-24 16:12 ` SZEDER Gábor
  1 sibling, 1 reply; 8+ messages in thread
From: Felipe Contreras @ 2013-05-24 13:11 UTC (permalink / raw)
  To: Ramkumar Ramachandra; +Cc: Git List, SZEDER Gábor

On Fri, May 24, 2013 at 6:33 AM, Ramkumar Ramachandra
<artagnon@gmail.com> wrote:
> Hi,
>
> I'm not able to sort completions for some weird reason.  No matter
> what I order I insert stuff into COMPREPLY, bash seems to auto-sort
> them lexically.  I tried to pass --sort='-committerdate' to git
> for-each-ref so I can get a sensible 'git checkout <TAB>' reply, and
> I'm very annoyed that it doesn't work.
>
> I thought it was bash's complete builtin doing the implicit sorting,
> so I read the manual with no success.  Is readline doing it?  If so,
> why am I not getting the ordering even in zsh (which doesn't use
> readline)?
>
> What am I missing?

AFAIK bash needs the completions sorted, so we added some | sort |
uniq. I suppose zsh doesn't need that, but have you tried by calling
compadd directly?

-- 
Felipe Contreras

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [QUERY] How do you sort completions?
  2013-05-24 11:33 [QUERY] How do you sort completions? Ramkumar Ramachandra
  2013-05-24 13:11 ` Felipe Contreras
@ 2013-05-24 16:12 ` SZEDER Gábor
  2013-05-24 16:18   ` Ramkumar Ramachandra
  1 sibling, 1 reply; 8+ messages in thread
From: SZEDER Gábor @ 2013-05-24 16:12 UTC (permalink / raw)
  To: Ramkumar Ramachandra; +Cc: Git List, Felipe Contreras

Hi,


On Fri, May 24, 2013 at 05:03:27PM +0530, Ramkumar Ramachandra wrote:
> I'm not able to sort completions for some weird reason.  No matter
> what I order I insert stuff into COMPREPLY, bash seems to auto-sort
> them lexically.  I tried to pass --sort='-committerdate' to git
> for-each-ref so I can get a sensible 'git checkout <TAB>' reply, and
> I'm very annoyed that it doesn't work.
> 
> I thought it was bash's complete builtin doing the implicit sorting,
> so I read the manual with no success.  Is readline doing it?  If so,
> why am I not getting the ordering even in zsh (which doesn't use
> readline)?

The order of elements in COMPREPLY doesn't matter, it will be sorted
anyway:

$ _foo () { COMPREPLY=("foo" "bar" "baz") ; }
$ complete -F _foo foo
$ foo <TAB>
bar  baz  foo

I don't know who does the sorting (Bash or readline), and I don't know
any way to disable it.


Gábor

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [QUERY] How do you sort completions?
  2013-05-24 16:12 ` SZEDER Gábor
@ 2013-05-24 16:18   ` Ramkumar Ramachandra
  2013-05-24 16:22     ` Antoine Pelisse
  2013-05-24 18:20     ` Marc Khouzam
  0 siblings, 2 replies; 8+ messages in thread
From: Ramkumar Ramachandra @ 2013-05-24 16:18 UTC (permalink / raw)
  To: SZEDER Gábor; +Cc: Git List, Felipe Contreras

SZEDER Gábor wrote:
> I don't know who does the sorting (Bash or readline), and I don't know
> any way to disable it.

Damn; so it's impossible to have a custom-sorted completion list in
bash.  Any idea about zsh?  I know that there are completion groups,
but I'd really like custom sorting.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [QUERY] How do you sort completions?
  2013-05-24 16:18   ` Ramkumar Ramachandra
@ 2013-05-24 16:22     ` Antoine Pelisse
  2013-05-24 18:26       ` Ramkumar Ramachandra
  2013-05-24 18:20     ` Marc Khouzam
  1 sibling, 1 reply; 8+ messages in thread
From: Antoine Pelisse @ 2013-05-24 16:22 UTC (permalink / raw)
  To: Ramkumar Ramachandra; +Cc: SZEDER Gábor, Git List, Felipe Contreras

On Fri, May 24, 2013 at 6:18 PM, Ramkumar Ramachandra
<artagnon@gmail.com> wrote:
> Damn; so it's impossible to have a custom-sorted completion list in
> bash.  Any idea about zsh?  I know that there are completion groups,
> but I'd really like custom sorting.

I think sorting is required for faster look-up, most likely with
dichotomic search. Otherwise it would have to search the whole list
each time.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [QUERY] How do you sort completions?
  2013-05-24 16:18   ` Ramkumar Ramachandra
  2013-05-24 16:22     ` Antoine Pelisse
@ 2013-05-24 18:20     ` Marc Khouzam
  1 sibling, 0 replies; 8+ messages in thread
From: Marc Khouzam @ 2013-05-24 18:20 UTC (permalink / raw)
  To: 'Ramkumar Ramachandra', 'SZEDER Gábor'
  Cc: 'Git List', 'Felipe Contreras'


> -----Original Message-----
> From: git-owner@vger.kernel.org 
> [mailto:git-owner@vger.kernel.org] On Behalf Of Ramkumar Ramachandra
> Sent: Friday, May 24, 2013 12:19 PM
> To: SZEDER Gábor
> Cc: Git List; Felipe Contreras
> Subject: Re: [QUERY] How do you sort completions?
> 
> SZEDER Gábor wrote:
> > I don't know who does the sorting (Bash or readline), and I 
> don't know
> > any way to disable it.
> 
> Damn; so it's impossible to have a custom-sorted completion list in
> bash.  Any idea about zsh?  I know that there are completion groups,
> but I'd really like custom sorting.

You could do that with tcsh :)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [QUERY] How do you sort completions?
  2013-05-24 16:22     ` Antoine Pelisse
@ 2013-05-24 18:26       ` Ramkumar Ramachandra
  0 siblings, 0 replies; 8+ messages in thread
From: Ramkumar Ramachandra @ 2013-05-24 18:26 UTC (permalink / raw)
  To: Antoine Pelisse; +Cc: SZEDER Gábor, Git List, Felipe Contreras

Antoine Pelisse wrote:
> I think sorting is required for faster look-up, most likely with
> dichotomic search. Otherwise it would have to search the whole list
> each time.

Oh, it's probably keeping just one copy of the completions in memory
(which has to be sorted for search); this is also used to display.
Makes sense, although I would have expected the shell to keep two
copies: a sorted one for searching through, and another preserving the
original order for displaying.  I suppose they didn't think of it.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [QUERY] How do you sort completions?
  2013-05-24 13:11 ` Felipe Contreras
@ 2013-05-28 10:23   ` SZEDER Gábor
  0 siblings, 0 replies; 8+ messages in thread
From: SZEDER Gábor @ 2013-05-28 10:23 UTC (permalink / raw)
  To: Felipe Contreras; +Cc: Ramkumar Ramachandra, Git List

Hi,

On Fri, May 24, 2013 at 08:11:00AM -0500, Felipe Contreras wrote:
> AFAIK bash needs the completions sorted, so we added some | sort |
> uniq.

Actually, it seems to sort and remove duplicates automatically:

$ _foo () { COMPREPLY=("bar" "foo" "bar" "baz") ; }
$ complete -F _foo foo
$ foo <TAB>
bar  baz  foo  

So that | sort | uniq might not be necessary after all, and by
removing them we could spare two fork()+exec()s.

I'm not sure all supported Bash versions behave this way, though.


Best,
Gábor

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2013-05-28 10:23 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-24 11:33 [QUERY] How do you sort completions? Ramkumar Ramachandra
2013-05-24 13:11 ` Felipe Contreras
2013-05-28 10:23   ` SZEDER Gábor
2013-05-24 16:12 ` SZEDER Gábor
2013-05-24 16:18   ` Ramkumar Ramachandra
2013-05-24 16:22     ` Antoine Pelisse
2013-05-24 18:26       ` Ramkumar Ramachandra
2013-05-24 18:20     ` Marc Khouzam

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).