Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep sorting for completions #361

Closed
terlar opened this issue Oct 22, 2012 · 5 comments
Closed

Keep sorting for completions #361

terlar opened this issue Oct 22, 2012 · 5 comments
Assignees
Milestone

Comments

@terlar
Copy link
Contributor

terlar commented Oct 22, 2012

If I have a completion method that returns results in the relevant order, I'd like to have the possibility to keep this order instead of sorting alphabetically.

Perhaps a switch that tells the completion to leave this alone?

@terlar
Copy link
Contributor Author

terlar commented Jan 19, 2013

I can explain a use case for this. For example the completions that use git branches and tags.

Right now if I run git checkout <Tab> then all the tags will appear first and amongst them the oldest ones first since they have a lower number. In my use case those are the least likely to be checked out.

Because of this I created a completion that returned branches and tags in order of relevance.

  • First local branches
  • Then tags and branches in order of last commit

The benefit of this is that I quickly can see the branches I work on in the completion, see which branches are active on the remote and finally which tags are most recent without having to scan through all the old ones.

gladhorn added a commit to gladhorn/fish-shell that referenced this issue Aug 3, 2016
This is convenient when doing things like git log where most likely the
first results are more relevant than later ones.

Now it's possible to use complete ... -S '(my command)' and similar.

See fish-shell#361
gladhorn added a commit to gladhorn/fish-shell that referenced this issue Aug 3, 2016
This is convenient when doing things like git log where most likely the
first results are more relevant than later ones.

Now it's possible to use complete ... -S '(my command)' and similar.

See fish-shell#361
@danielcompton
Copy link

This would be a really great feature, I also have the same problem where tags are sorted ahead of branches.

@ridiculousfish ridiculousfish self-assigned this Nov 19, 2016
@ridiculousfish
Copy link
Member

I wonder how bad it would be to only sort file completions. I'll take a crack at this.

@krader1961
Copy link
Contributor

FYI: Some completion scripts do not deduplicate their output and instead rely on the existing fish sorting of the suggestions to do so. So if this is ever implemented we need to decided whether to retain de-duping of the suggestions without sorting them or require that such completions handle the de-duping on their own.

@mqudsi
Copy link
Contributor

mqudsi commented Jul 24, 2017

I just ran into this with git commit --fixup, where fish actually ends up sorting all commits ever by sha1 instead of showing them in reverse order, rendering completions useless here.

mqudsi added a commit to mqudsi/fish-shell that referenced this issue Jul 24, 2017
This fixes fish-shell#361 [0], while addressing the
reservations made in the comments. In particular, this patch introduces
a -k/--keep-order switch to `complete` that can be used to prevent fish
from sorting/re-ordering the results provided by a completion source.

In addition, this patch does so without doing away with deduplication of
completions by introducing a new unique_unsorted(..) helper function
that removes duplicates in-place without affecting the general order of
the vector/container.

Note that the code now uses a /stable/ sort for completions, since the
behavior of is_naturally_less_than as of this patch now means that the
results are not necessarily _actually_ identical just because that
function repeatedly returns false for any ordering of any given two
elements.

[0]: fish-shell#361
mqudsi added a commit to mqudsi/fish-shell that referenced this issue Jul 24, 2017
The primary motivation for --keep-order for `complete` was to support
something like commit history completions, which are returned by git in
reverse chronological order and make no sense alphabetically (they are
SHA1 hashes).

See fish-shell#361 for more info.
@krader1961 krader1961 marked this as a duplicate of #3284 Jul 26, 2017
@krader1961 krader1961 modified the milestones: fish-3.0, fish-future Jul 26, 2017
krader1961 pushed a commit that referenced this issue Jul 26, 2017
Introduce a -k/--keep-order switch to `complete` that can be used to
prevent fish from sorting/re-ordering the results provided by a completion
source.

In addition, this patch does so without doing away with deduplication
of completions by introducing a new unique_unsorted(..) helper function
that removes duplicates in-place without affecting the general order of
the vector/container.

Note that the code now uses a stable sort for completions, since the
behavior of is_naturally_less_than as of this patch now means that the
results are not necessarily _actually_ identical just because that function
repeatedly returns false for any ordering of any given two elements.

Fixes #361
krader1961 pushed a commit that referenced this issue Jul 26, 2017
The primary motivation for --keep-order for `complete` was to support
something like commit history completions, which are returned by git in
reverse chronological order and make no sense alphabetically (they are
SHA1 hashes).

See #361 for more info.
mqudsi added a commit that referenced this issue Sep 10, 2017
Addresses the main concern of #3830 by preserving the internal ordering
of tag/branch listings generated by git. Fixes mixing of remote and
local branches in completions.

Does not address the concern of having local branches on top, remote
branches after, and tags at the bottom - I don't believe we have that
functionality available to us yet. #361 only implemented sort within a
category of completions, but there is no category "weight" unless I'm
mistaken.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants