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
Comments
I can explain a use case for this. For example the completions that use git branches and tags. Right now if I run Because of this I created a completion that returned branches and tags in order of relevance.
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. |
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
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
This would be a really great feature, I also have the same problem where tags are sorted ahead of branches. |
I wonder how bad it would be to only sort file completions. I'll take a crack at this. |
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. |
I just ran into this with |
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
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.
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
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.
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.
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?
The text was updated successfully, but these errors were encountered: