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

Comments

Projects
None yet
6 participants
@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

This comment has been minimized.

Copy link
Contributor

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.

@faho faho added the enhancement label Aug 3, 2016

gladhorn added a commit to gladhorn/fish-shell that referenced this issue Aug 3, 2016

Make it possible to have complete not sort
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

Make it possible to have complete not sort
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

This comment has been minimized.

Copy link

danielcompton commented Nov 18, 2016

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

This comment has been minimized.

Copy link
Member

ridiculousfish commented Nov 19, 2016

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

@krader1961

This comment has been minimized.

Copy link
Contributor

krader1961 commented Apr 12, 2017

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

This comment has been minimized.

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

Added option to use completion source order without re-sorting
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

Using new complete --keep-order option for __fish_git_recent_commits
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 added a commit that referenced this issue Jul 26, 2017

Added option to use completion source order without re-sorting
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 added a commit that referenced this issue Jul 26, 2017

Using new complete --keep-order option for __fish_git_recent_commits
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.

@krader1961 krader1961 closed this Jul 26, 2017

mqudsi added a commit that referenced this issue Sep 10, 2017

Preserve git's own ordering of branch/tag completions for checkout
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment