Skip to content

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
Contributor

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