mirror of
https://github.com/nushell/nu_scripts.git
synced 2024-09-11 13:45:56 +03:00
completions/git: fix support for path relative to current directory (#666)
Continuing effort on https://github.com/nushell/nu_scripts/pull/617 which only auto-completes path relative to git root. Before, ``` $ cd src/ $ git add <tab> src/main.rs Modified README.md Untracked $ git diff <tab> src/main.rs ``` Now it displays, ``` $ cd src/ $ git add <tab> main.rs Modified ../README.md Untracked $ git diff <tab> main.rs ```
This commit is contained in:
parent
27ffa41815
commit
8635a78991
@ -88,23 +88,37 @@ def "nu-complete git tags" [] {
|
|||||||
# 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 = {
|
||||||
" D": "Deleted"
|
".D": "Deleted"
|
||||||
" M": "Modified"
|
".M": "Modified"
|
||||||
"!!": "Ignored"
|
"!" : "Ignored"
|
||||||
"??": "Untracked"
|
"?" : "Untracked"
|
||||||
"AU": "Staged, not merged"
|
"AU": "Staged, not merged"
|
||||||
"MD": "Some modifications staged, file deleted in work tree"
|
"MD": "Some modifications staged, file deleted in work tree"
|
||||||
"MM": "Some modifications staged, some modifications untracked"
|
"MM": "Some modifications staged, some modifications untracked"
|
||||||
"R ": "Renamed"
|
"R.": "Renamed"
|
||||||
|
"UU": "Both modified (in merge conflict)"
|
||||||
}
|
}
|
||||||
|
|
||||||
def "nu-complete git files" [] {
|
def "nu-complete git files" [] {
|
||||||
let relevant_statuses = ["??"," M", "MM", "MD", " D"]
|
let relevant_statuses = ["?",".M", "MM", "MD", ".D", "UU"]
|
||||||
^git status --porcelain
|
^git status -uall --porcelain=2
|
||||||
| lines
|
| lines
|
||||||
| parse --regex "(?P<short_status>.{2}) (?P<value>.+)"
|
| each { |$it|
|
||||||
| where $it.short_status in $relevant_statuses
|
if $it starts-with "1 " {
|
||||||
| insert "description" { |e| $short_status_descriptions | get $e.short_status}
|
$it | parse --regex "1 (?P<short_status>\\S+) (?:\\S+\\s?){6} (?P<value>\\S+)"
|
||||||
|
} else if $it starts-with "2 " {
|
||||||
|
$it | parse --regex "2 (?P<short_status>\\S+) (?:\\S+\\s?){6} (?P<value>\\S+)"
|
||||||
|
} else if $it starts-with "u " {
|
||||||
|
$it | parse --regex "u (?P<short_status>\\S+) (?:\\S+\\s?){8} (?P<value>\\S+)"
|
||||||
|
} else if $it starts-with "? " {
|
||||||
|
$it | parse --regex "(?P<short_status>.{1}) (?P<value>.+)"
|
||||||
|
} else {
|
||||||
|
{ short_status: 'unknown', value: $it }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
| flatten
|
||||||
|
| where $it.short_status in $relevant_statuses
|
||||||
|
| insert "description" { |e| $short_status_descriptions | get $e.short_status}
|
||||||
}
|
}
|
||||||
|
|
||||||
def "nu-complete git built-in-refs" [] {
|
def "nu-complete git built-in-refs" [] {
|
||||||
|
Loading…
Reference in New Issue
Block a user