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

✨ unsort the completions in git checkout #1022

Merged
merged 2 commits into from
Jan 27, 2025

Conversation

AucaCoyan
Copy link
Contributor

motivation

Hi! This is something I wanted since #14424 of nushell/nushell landed.
Unsorted completions on the git checkout command

The problem

is that git checkout accepts lots of things: commits hashes, filenames, local branches and remote branches. Since the mentioned pr all the completions were sorted, but for this command it didn't make sense.
I used git switch to checkout a branch for the time being, but it's a little annoying that you can't push "unsorted" completions on a command.

the result

With the help of ysthakur and weirdan, I managed to achieve this:

git checkout <tab>

before: (these are sorted)
image

after: (these aren't)
image

How?

Citing the docs:
https://www.nushell.sh/book/custom_completions.html#options-for-custom-completions

    {
        options: {
            case_sensitive: false,
            completion_algorithm: prefix,
            positional: false,
            sort: false,
        },
        completions: [cat, rat, bat]
    }
}

and I passed a table to the completions key, instead of a list.

    completions: $table_of_checkouts

@fdncred
Copy link
Collaborator

fdncred commented Jan 27, 2025

agreed. thanks!

@fdncred fdncred merged commit fff77c7 into nushell:main Jan 27, 2025
1 check passed
@AucaCoyan AucaCoyan deleted the better-git-checkout-completions branch January 27, 2025 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants