Skip to content

Commit fff77c7

Browse files
authored
✨ unsort the completions in git checkout (#1022)
### motivation Hi! This is something I wanted since [#14424 of nushell/nushell](nushell/nushell#14424) 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](https://github.com/user-attachments/assets/ad495b29-e418-426f-9bbe-2056f34b819f) after: (these aren't) ![image](https://github.com/user-attachments/assets/e2b5d647-cccb-4e0b-b1c2-b80781ada3ec) ### 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 ```
1 parent e245718 commit fff77c7

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

custom-completions/git/git-completions.nu

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def "nu-complete git switch" [] {
5353
}
5454

5555
def "nu-complete git checkout" [] {
56-
(nu-complete git local branches)
56+
let table_of_checkouts = (nu-complete git local branches)
5757
| parse "{value}"
5858
| insert description "local branch"
5959
| append (nu-complete git remote branches nonlocal without prefix
@@ -64,7 +64,15 @@ def "nu-complete git checkout" [] {
6464
| insert description "remote branch")
6565
| append (nu-complete git files | where description != "Untracked" | select value | insert description "git file")
6666
| append (nu-complete git commits all)
67-
| append (nu-complete git files | where description != "Untracked" | select value)
67+
68+
return {
69+
options: {
70+
case_sensitive: false,
71+
completion_algorithm: prefix,
72+
sort: false,
73+
},
74+
completions: $table_of_checkouts
75+
}
6876
}
6977

7078
# Arguments to `git rebase --onto <arg1> <arg2>`
@@ -125,7 +133,7 @@ def "nu-complete git files" [] {
125133
def "nu-complete git built-in-refs" [] {
126134
[HEAD FETCH_HEAD ORIG_HEAD]
127135
}
128-
136+
129137
def "nu-complete git refs" [] {
130138
nu-complete git local branches
131139
| parse "{value}"

0 commit comments

Comments
 (0)