{"thread":{"id":"33918","subject":"[QUERY] How do you sort completions?","startedAt":"2013-05-24T11:33:27Z","lastAt":"2013-05-28T10:23:03Z","messageCount":8,"participants":["Ramkumar Ramachandra","Felipe Contreras","SZEDER Gábor","Antoine Pelisse","Marc Khouzam"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"218362","messageId":"CALkWK0k=nVHOBe5SgRH9xQK1+yAYBzbNMqsWxhYPo0MTZPp63g@mail.gmail.com","threadId":"33918","inReplyTo":null,"subject":"[QUERY] How do you sort completions?","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-05-24T11:33:27Z","receivedAt":"2013-05-24T11:33:27Z","isPatch":false,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi,\n\nI'm not able to sort completions for some weird reason.  No matter\nwhat I order I insert stuff into COMPREPLY, bash seems to auto-sort\nthem lexically.  I tried to pass --sort='-committerdate' to git\nfor-each-ref so I can get a sensible 'git checkout <TAB>' reply, and\nI'm very annoyed that it doesn't work.\n\nI thought it was bash's complete builtin doing the implicit sorting,\nso I read the manual with no success.  Is readline doing it?  If so,\nwhy am I not getting the ordering even in zsh (which doesn't use\nreadline)?\n\nWhat am I missing?\n\nRam\n"},{"id":"218365","messageId":"CAMP44s3_BBPu0WSzYyaVLbdg0dBuaV7MFgy1SMuK1C8P2vKbYg@mail.gmail.com","threadId":"33918","inReplyTo":"CALkWK0k=nVHOBe5SgRH9xQK1+yAYBzbNMqsWxhYPo0MTZPp63g@mail.gmail.com","subject":"Re: [QUERY] How do you sort completions?","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-05-24T13:11:00Z","receivedAt":"2013-05-24T13:11:00Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Fri, May 24, 2013 at 6:33 AM, Ramkumar Ramachandra\n<artagnon@gmail.com> wrote:\n> Hi,\n>\n> I'm not able to sort completions for some weird reason.  No matter\n> what I order I insert stuff into COMPREPLY, bash seems to auto-sort\n> them lexically.  I tried to pass --sort='-committerdate' to git\n> for-each-ref so I can get a sensible 'git checkout <TAB>' reply, and\n> I'm very annoyed that it doesn't work.\n>\n> I thought it was bash's complete builtin doing the implicit sorting,\n> so I read the manual with no success.  Is readline doing it?  If so,\n> why am I not getting the ordering even in zsh (which doesn't use\n> readline)?\n>\n> What am I missing?\n\nAFAIK bash needs the completions sorted, so we added some | sort |\nuniq. I suppose zsh doesn't need that, but have you tried by calling\ncompadd directly?\n\n-- \nFelipe Contreras\n"},{"id":"218386","messageId":"20130524161243.GB2104@goldbirke","threadId":"33918","inReplyTo":"CALkWK0k=nVHOBe5SgRH9xQK1+yAYBzbNMqsWxhYPo0MTZPp63g@mail.gmail.com","subject":"Re: [QUERY] How do you sort completions?","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2013-05-24T16:12:43Z","receivedAt":"2013-05-24T16:12:43Z","isPatch":false,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi,\n\n\nOn Fri, May 24, 2013 at 05:03:27PM +0530, Ramkumar Ramachandra wrote:\n> I'm not able to sort completions for some weird reason.  No matter\n> what I order I insert stuff into COMPREPLY, bash seems to auto-sort\n> them lexically.  I tried to pass --sort='-committerdate' to git\n> for-each-ref so I can get a sensible 'git checkout <TAB>' reply, and\n> I'm very annoyed that it doesn't work.\n> \n> I thought it was bash's complete builtin doing the implicit sorting,\n> so I read the manual with no success.  Is readline doing it?  If so,\n> why am I not getting the ordering even in zsh (which doesn't use\n> readline)?\n\nThe order of elements in COMPREPLY doesn't matter, it will be sorted\nanyway:\n\n$ _foo () { COMPREPLY=(\"foo\" \"bar\" \"baz\") ; }\n$ complete -F _foo foo\n$ foo <TAB>\nbar  baz  foo\n\nI don't know who does the sorting (Bash or readline), and I don't know\nany way to disable it.\n\n\nGábor\n"},{"id":"218388","messageId":"CALkWK0n8iuwNHfxV4AHUV+721pqLUOPhM6h+e0_opmkVuOV_4A@mail.gmail.com","threadId":"33918","inReplyTo":"20130524161243.GB2104@goldbirke","subject":"Re: [QUERY] How do you sort completions?","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-05-24T16:18:41Z","receivedAt":"2013-05-24T16:18:41Z","isPatch":false,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"SZEDER Gábor wrote:\n> I don't know who does the sorting (Bash or readline), and I don't know\n> any way to disable it.\n\nDamn; so it's impossible to have a custom-sorted completion list in\nbash.  Any idea about zsh?  I know that there are completion groups,\nbut I'd really like custom sorting.\n"},{"id":"218390","messageId":"CALWbr2xxND4xz49jmwXUTTr1f=Z3nmHCTQd+bBcK_Etv5oB0Fg@mail.gmail.com","threadId":"33918","inReplyTo":"CALkWK0n8iuwNHfxV4AHUV+721pqLUOPhM6h+e0_opmkVuOV_4A@mail.gmail.com","subject":"Re: [QUERY] How do you sort completions?","fromName":"Antoine Pelisse","fromEmail":"apelisse@gmail.com","sentAt":"2013-05-24T16:22:02Z","receivedAt":"2013-05-24T16:22:02Z","isPatch":false,"sender":{"key":"apelisse@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1929644?v=4"},"body":"On Fri, May 24, 2013 at 6:18 PM, Ramkumar Ramachandra\n<artagnon@gmail.com> wrote:\n> Damn; so it's impossible to have a custom-sorted completion list in\n> bash.  Any idea about zsh?  I know that there are completion groups,\n> but I'd really like custom sorting.\n\nI think sorting is required for faster look-up, most likely with\ndichotomic search. Otherwise it would have to search the whole list\neach time.\n"},{"id":"218410","messageId":"E59706EF8DB1D147B15BECA3322E4BDC1BF6DA0E@eusaamb103.ericsson.se","threadId":"33918","inReplyTo":"CALkWK0n8iuwNHfxV4AHUV+721pqLUOPhM6h+e0_opmkVuOV_4A@mail.gmail.com","subject":"RE: [QUERY] How do you sort completions?","fromName":"Marc Khouzam","fromEmail":"marc.khouzam@ericsson.com","sentAt":"2013-05-24T18:20:24Z","receivedAt":"2013-05-24T18:20:24Z","isPatch":false,"sender":{"key":"marc.khouzam@ericsson.com","avatar":"https://gravatar.com/avatar/de564e23ad14e2945f9f1cdb4d0227c935b5b54c39576a304d47caa3e23dcd33?d=mp&s=160"},"body":"\n> -----Original Message-----\n> From: git-owner@vger.kernel.org \n> [mailto:git-owner@vger.kernel.org] On Behalf Of Ramkumar Ramachandra\n> Sent: Friday, May 24, 2013 12:19 PM\n> To: SZEDER Gábor\n> Cc: Git List; Felipe Contreras\n> Subject: Re: [QUERY] How do you sort completions?\n> \n> SZEDER Gábor wrote:\n> > I don't know who does the sorting (Bash or readline), and I \n> don't know\n> > any way to disable it.\n> \n> Damn; so it's impossible to have a custom-sorted completion list in\n> bash.  Any idea about zsh?  I know that there are completion groups,\n> but I'd really like custom sorting.\n\nYou could do that with tcsh :)"},{"id":"218409","messageId":"CALkWK0k=yGmAvOsGO+4hS6bU=Y4mJoCq6QqVoSNajBYHaPxGng@mail.gmail.com","threadId":"33918","inReplyTo":"CALWbr2xxND4xz49jmwXUTTr1f=Z3nmHCTQd+bBcK_Etv5oB0Fg@mail.gmail.com","subject":"Re: [QUERY] How do you sort completions?","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-05-24T18:26:09Z","receivedAt":"2013-05-24T18:26:09Z","isPatch":false,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Antoine Pelisse wrote:\n> I think sorting is required for faster look-up, most likely with\n> dichotomic search. Otherwise it would have to search the whole list\n> each time.\n\nOh, it's probably keeping just one copy of the completions in memory\n(which has to be sorted for search); this is also used to display.\nMakes sense, although I would have expected the shell to keep two\ncopies: a sorted one for searching through, and another preserving the\noriginal order for displaying.  I suppose they didn't think of it.\n"},{"id":"218638","messageId":"20130528102303.GC2192@goldbirke","threadId":"33918","inReplyTo":"CAMP44s3_BBPu0WSzYyaVLbdg0dBuaV7MFgy1SMuK1C8P2vKbYg@mail.gmail.com","subject":"Re: [QUERY] How do you sort completions?","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2013-05-28T10:23:03Z","receivedAt":"2013-05-28T10:23:03Z","isPatch":false,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi,\n\nOn Fri, May 24, 2013 at 08:11:00AM -0500, Felipe Contreras wrote:\n> AFAIK bash needs the completions sorted, so we added some | sort |\n> uniq.\n\nActually, it seems to sort and remove duplicates automatically:\n\n$ _foo () { COMPREPLY=(\"bar\" \"foo\" \"bar\" \"baz\") ; }\n$ complete -F _foo foo\n$ foo <TAB>\nbar  baz  foo  \n\nSo that | sort | uniq might not be necessary after all, and by\nremoving them we could spare two fork()+exec()s.\n\nI'm not sure all supported Bash versions behave this way, though.\n\n\nBest,\nGábor\n"}]}