mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-02 07:07:46 +00:00
Improve panache-git performance for changes with many files (#240)
This commit is contained in:
parent
456c0fe5b0
commit
4ab39c0d09
1 changed files with 8 additions and 21 deletions
|
@ -3,14 +3,14 @@
|
||||||
#
|
#
|
||||||
# Quick Start:
|
# Quick Start:
|
||||||
# - Download this script (panache-git.nu)
|
# - Download this script (panache-git.nu)
|
||||||
# - In your Nushell config file:
|
# - In your Nushell config:
|
||||||
# - Source this script
|
# - Source this script
|
||||||
# - Set panache-git as your prompt command
|
# - Set panache-git as your prompt command
|
||||||
# - Disable the separate prompt indicator by setting it to an empty string
|
# - Disable the separate prompt indicator by setting it to an empty string
|
||||||
# - For example, with this script in your home directory:
|
# - For example, with this script in your home directory:
|
||||||
# source ~/panache-git.nu
|
# source ~/panache-git.nu
|
||||||
# let-env PROMPT_COMMAND = { panache-git }
|
# let-env PROMPT_COMMAND = { panache-git }
|
||||||
# let-env PROMPT_INDICATOR = ""
|
# let-env PROMPT_INDICATOR = { "" }
|
||||||
# - Restart Nushell
|
# - Restart Nushell
|
||||||
#
|
#
|
||||||
# For more documentation or to file an issue, see https://github.com/ehdevries/panache-git
|
# For more documentation or to file an issue, see https://github.com/ehdevries/panache-git
|
||||||
|
@ -38,20 +38,18 @@ module panache-plumbing {
|
||||||
$'(ansi reset)($current-dir-abbreviated)'
|
$'(ansi reset)($current-dir-abbreviated)'
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get repository status as raw text
|
|
||||||
export def "panache-git raw" [] {
|
|
||||||
do --ignore-errors { git --no-optional-locks status --porcelain=2 --branch } | str collect
|
|
||||||
}
|
|
||||||
|
|
||||||
# Get repository status as structured data
|
# Get repository status as structured data
|
||||||
export def "panache-git structured" [] {
|
export def "panache-git structured" [] {
|
||||||
let status = (panache-git raw)
|
let in-git-repo = (do --ignore-errors { git rev-parse --abbrev-ref HEAD } | empty? | nope)
|
||||||
|
|
||||||
let in-git-repo = ($status | empty? | nope)
|
let status = (if $in-git-repo {
|
||||||
|
git --no-optional-locks status --porcelain=2 --branch | lines
|
||||||
|
} else {
|
||||||
|
[]
|
||||||
|
})
|
||||||
|
|
||||||
let on-named-branch = (if $in-git-repo {
|
let on-named-branch = (if $in-git-repo {
|
||||||
$status
|
$status
|
||||||
| lines
|
|
||||||
| where ($it | str starts-with '# branch.head')
|
| where ($it | str starts-with '# branch.head')
|
||||||
| first
|
| first
|
||||||
| str contains '(detached)'
|
| str contains '(detached)'
|
||||||
|
@ -62,7 +60,6 @@ module panache-plumbing {
|
||||||
|
|
||||||
let branch-name = (if $on-named-branch {
|
let branch-name = (if $on-named-branch {
|
||||||
$status
|
$status
|
||||||
| lines
|
|
||||||
| where ($it | str starts-with '# branch.head')
|
| where ($it | str starts-with '# branch.head')
|
||||||
| split column ' ' col1 col2 branch
|
| split column ' ' col1 col2 branch
|
||||||
| get branch
|
| get branch
|
||||||
|
@ -73,7 +70,6 @@ module panache-plumbing {
|
||||||
|
|
||||||
let commit-hash = (if $in-git-repo {
|
let commit-hash = (if $in-git-repo {
|
||||||
$status
|
$status
|
||||||
| lines
|
|
||||||
| where ($it | str starts-with '# branch.oid')
|
| where ($it | str starts-with '# branch.oid')
|
||||||
| split column ' ' col1 col2 full_hash
|
| split column ' ' col1 col2 full_hash
|
||||||
| get full_hash
|
| get full_hash
|
||||||
|
@ -85,7 +81,6 @@ module panache-plumbing {
|
||||||
|
|
||||||
let tracking-upstream-branch = (if $in-git-repo {
|
let tracking-upstream-branch = (if $in-git-repo {
|
||||||
$status
|
$status
|
||||||
| lines
|
|
||||||
| where ($it | str starts-with '# branch.upstream')
|
| where ($it | str starts-with '# branch.upstream')
|
||||||
| str collect
|
| str collect
|
||||||
| empty?
|
| empty?
|
||||||
|
@ -96,7 +91,6 @@ module panache-plumbing {
|
||||||
|
|
||||||
let upstream-exists-on-remote = (if $in-git-repo {
|
let upstream-exists-on-remote = (if $in-git-repo {
|
||||||
$status
|
$status
|
||||||
| lines
|
|
||||||
| where ($it | str starts-with '# branch.ab')
|
| where ($it | str starts-with '# branch.ab')
|
||||||
| str collect
|
| str collect
|
||||||
| empty?
|
| empty?
|
||||||
|
@ -107,7 +101,6 @@ module panache-plumbing {
|
||||||
|
|
||||||
let ahead-behind-table = (if $upstream-exists-on-remote {
|
let ahead-behind-table = (if $upstream-exists-on-remote {
|
||||||
$status
|
$status
|
||||||
| lines
|
|
||||||
| where ($it | str starts-with '# branch.ab')
|
| where ($it | str starts-with '# branch.ab')
|
||||||
| split column ' ' col1 col2 ahead behind
|
| split column ' ' col1 col2 ahead behind
|
||||||
} else {
|
} else {
|
||||||
|
@ -135,7 +128,6 @@ module panache-plumbing {
|
||||||
|
|
||||||
let has-staging-or-worktree-changes = (if $in-git-repo {
|
let has-staging-or-worktree-changes = (if $in-git-repo {
|
||||||
$status
|
$status
|
||||||
| lines
|
|
||||||
| where ($it | str starts-with '1') || ($it | str starts-with '2')
|
| where ($it | str starts-with '1') || ($it | str starts-with '2')
|
||||||
| str collect
|
| str collect
|
||||||
| empty?
|
| empty?
|
||||||
|
@ -146,7 +138,6 @@ module panache-plumbing {
|
||||||
|
|
||||||
let has-untracked-files = (if $in-git-repo {
|
let has-untracked-files = (if $in-git-repo {
|
||||||
$status
|
$status
|
||||||
| lines
|
|
||||||
| where ($it | str starts-with '?')
|
| where ($it | str starts-with '?')
|
||||||
| str collect
|
| str collect
|
||||||
| empty?
|
| empty?
|
||||||
|
@ -157,7 +148,6 @@ module panache-plumbing {
|
||||||
|
|
||||||
let has-unresolved-merge-conflicts = (if $in-git-repo {
|
let has-unresolved-merge-conflicts = (if $in-git-repo {
|
||||||
$status
|
$status
|
||||||
| lines
|
|
||||||
| where ($it | str starts-with 'u')
|
| where ($it | str starts-with 'u')
|
||||||
| str collect
|
| str collect
|
||||||
| empty?
|
| empty?
|
||||||
|
@ -168,7 +158,6 @@ module panache-plumbing {
|
||||||
|
|
||||||
let staging-worktree-table = (if $has-staging-or-worktree-changes {
|
let staging-worktree-table = (if $has-staging-or-worktree-changes {
|
||||||
$status
|
$status
|
||||||
| lines
|
|
||||||
| where ($it | str starts-with '1') || ($it | str starts-with '2')
|
| where ($it | str starts-with '1') || ($it | str starts-with '2')
|
||||||
| split column ' '
|
| split column ' '
|
||||||
| get column2
|
| get column2
|
||||||
|
@ -203,7 +192,6 @@ module panache-plumbing {
|
||||||
|
|
||||||
let untracked-count = (if $has-untracked-files {
|
let untracked-count = (if $has-untracked-files {
|
||||||
$status
|
$status
|
||||||
| lines
|
|
||||||
| where ($it | str starts-with '?')
|
| where ($it | str starts-with '?')
|
||||||
| length
|
| length
|
||||||
} else {
|
} else {
|
||||||
|
@ -228,7 +216,6 @@ module panache-plumbing {
|
||||||
|
|
||||||
let merge-conflict-count = (if $has-unresolved-merge-conflicts {
|
let merge-conflict-count = (if $has-unresolved-merge-conflicts {
|
||||||
$status
|
$status
|
||||||
| lines
|
|
||||||
| where ($it | str starts-with 'u')
|
| where ($it | str starts-with 'u')
|
||||||
| length
|
| length
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue