completions/git: add filename completion to diff and checkout (#617)

This commit is contained in:
Faïz Hernawan 2023-09-23 04:29:05 +07:00 committed by GitHub
parent c3086bc833
commit 9d0a182a86
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -63,6 +63,7 @@ def "nu-complete git checkout" [] {
| parse "{value}" | parse "{value}"
| insert description "remote branch") | insert description "remote branch")
| append (nu-complete git commits all) | append (nu-complete git commits all)
| append (nu-complete git files | where description != "Untracked" | select value)
} }
# Arguments to `git rebase --onto <arg1> <arg2>` # Arguments to `git rebase --onto <arg1> <arg2>`
@ -84,22 +85,6 @@ def "nu-complete git tags" [] {
^git tag | lines ^git tag | lines
} }
def "nu-complete git built-in-refs" [] {
[HEAD FETCH_HEAD ORIG_HEAD]
}
def "nu-complete git refs" [] {
nu-complete git switchable branches
| parse "{value}"
| insert description Branch
| append (nu-complete git tags | parse "{value}" | insert description Tag)
| append (nu-complete git built-in-refs)
}
def "nu-complete git subcommands" [] {
^git help -a | lines | where $it starts-with " " | parse -r '\s*(?P<value>[^ ]+) \s*(?P<description>\w.*)'
}
# See `man git-status` under "Short Format" # See `man git-status` under "Short Format"
# This is incomplete, but should cover the most common cases. # This is incomplete, but should cover the most common cases.
const short_status_descriptions = { const short_status_descriptions = {
@ -113,7 +98,7 @@ const short_status_descriptions = {
"R ": "Renamed" "R ": "Renamed"
} }
def "nu-complete git add" [] { def "nu-complete git files" [] {
let relevant_statuses = ["??"," M", "MM", "MD", " D"] let relevant_statuses = ["??"," M", "MM", "MD", " D"]
^git status --porcelain ^git status --porcelain
| lines | lines
@ -122,6 +107,35 @@ def "nu-complete git add" [] {
| insert "description" { |e| $short_status_descriptions | get $e.short_status} | insert "description" { |e| $short_status_descriptions | get $e.short_status}
} }
def "nu-complete git built-in-refs" [] {
[HEAD FETCH_HEAD ORIG_HEAD]
}
def "nu-complete git refs" [] {
nu-complete git switchable branches
| parse "{value}"
| insert description Branch
| append (nu-complete git tags | parse "{value}" | insert description Tag)
| append (nu-complete git built-in-refs)
}
def "nu-complete git files-or-refs" [] {
nu-complete git switchable branches
| parse "{value}"
| insert description Branch
| append (nu-complete git files | where description == "Modified" | select value)
| append (nu-complete git tags | parse "{value}" | insert description Tag)
| append (nu-complete git built-in-refs)
}
def "nu-complete git subcommands" [] {
^git help -a | lines | where $it starts-with " " | parse -r '\s*(?P<value>[^ ]+) \s*(?P<description>\w.*)'
}
def "nu-complete git add" [] {
nu-complete git files
}
# Check out git branches and files # Check out git branches and files
export extern "git checkout" [ export extern "git checkout" [
...targets: string@"nu-complete git checkout" # name of the branch or files to checkout ...targets: string@"nu-complete git checkout" # name of the branch or files to checkout
@ -337,7 +351,7 @@ export extern "git remote set-url" [
# Show changes between commits, working tree etc # Show changes between commits, working tree etc
export extern "git diff" [ export extern "git diff" [
rev1?: string@"nu-complete git refs" rev1_or_file?: string@"nu-complete git files-or-refs"
rev2?: string@"nu-complete git refs" rev2?: string@"nu-complete git refs"
--cached # show staged changes --cached # show staged changes
--name-only # only show names of changed files --name-only # only show names of changed files