1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 14:47:47 +00:00

Improve git checkout/switch completions (#358)

This commit is contained in:
Marc Schreiber 2023-01-23 13:05:43 +01:00 committed by GitHub
parent 3f41b8d179
commit e89b4ac6be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2,6 +2,16 @@ def "nu-complete git branches" [] {
^git branch | lines | each { |line| $line | str replace '\* ' "" | str trim }
}
def "nu-complete git switchable branches" [] {
let remotes_regex = (["(", ((nu-complete git remotes | each {|r| ['remotes/', $r, '/'] | str join}) | str join "|"), ")"] | str join)
^git branch -a
| lines
| parse -r (['^[\* ]+', $remotes_regex, '?(?P<branch>\w+)'] | flatten | str join)
| get branch
| uniq
| where {|branch| $branch != "HEAD"}
}
def "nu-complete git remotes" [] {
^git remote | lines | each { |line| $line | str trim }
}
@ -16,7 +26,7 @@ def "nu-complete git commits" [] {
# Check out git branches and files
export extern "git checkout" [
...targets: string@"nu-complete git branches" # name of the branch or files to checkout
...targets: string@"nu-complete git switchable branches" # name of the branch or files to checkout
--conflict: string # conflict style (merge or diff3)
--detach(-d) # detach HEAD at named commit
--force(-f) # force checkout (throw away local modifications)
@ -121,7 +131,7 @@ export extern "git push" [
# Switch between branches and commits
export extern "git switch" [
switch?: string@"nu-complete git branches" # name of branch to switch to
switch?: string@"nu-complete git switchable branches" # name of branch to switch to
--create(-c): string # create a new branch
--detach(-d): string@"nu-complete git log" # switch to a commit in a detatched state
--force-create(-C): string # forces creation of new branch, if it exists then the existing branch will be reset to starting point