mirror of
https://github.com/nushell/nu_scripts.git
synced 2024-08-16 08:50:31 +03:00
panache-git: do not print stderr from Git commands (#813)
Nushell 0.92 changed how external commands operate in pipelines: https://www.nushell.sh/blog/2024-04-02-nushell_0_92_0.html After updating to Nushell 0.92, panache-git would print errors when the current working directory was not a Git repository: "fatal: not a git repository (or any of the parent directories): .git" This change properly handles stderr from Git commands according to Nushell's updated external command behavior. Also, Nushell 0.91 introduced "is-not-empty", so places in the code where a string was checked for being not-empty or not-contains were simplified a bit. Finally, the main command in the module was renamed to "main" to make it simpler to import and use in config.
This commit is contained in:
parent
c30efc727b
commit
b1019dab18
@ -4,20 +4,20 @@
|
||||
# Quick Start:
|
||||
# - Download this file (panache-git.nu)
|
||||
# - In your Nushell config:
|
||||
# - Import the panache-git command from the panache-git.nu module file
|
||||
# - Import the main command from the panache-git.nu module file
|
||||
# - Set panache-git as your prompt command
|
||||
# - Disable the separate prompt indicator by setting it to an empty string
|
||||
# - For example, with this file in your home directory:
|
||||
# use ~/panache-git.nu panache-git
|
||||
# $env.PROMPT_COMMAND = { panache-git }
|
||||
# $env.PROMPT_INDICATOR = { "" }
|
||||
# use ~/panache-git.nu main
|
||||
# $env.PROMPT_COMMAND = {|| panache-git }
|
||||
# $env.PROMPT_INDICATOR = {|| "" }
|
||||
# - Restart Nushell
|
||||
#
|
||||
# For more documentation or to file an issue, see https://github.com/ehdevries/panache-git
|
||||
|
||||
|
||||
# An opinionated Git prompt for Nushell, styled after posh-git
|
||||
export def prompt-with-panache [] {
|
||||
export def main [] {
|
||||
let prompt = ($'(current-dir) (repo-styled)' | str trim)
|
||||
$'($prompt)> '
|
||||
}
|
||||
@ -30,7 +30,7 @@ export def current-dir [] {
|
||||
do --ignore-errors { $current_dir | path relative-to $nu.home-path } | str join
|
||||
)
|
||||
|
||||
let in_sub_dir_of_home = ($current_dir_relative_to_home | is-empty | nope)
|
||||
let in_sub_dir_of_home = ($current_dir_relative_to_home | is-not-empty)
|
||||
|
||||
let current_dir_abbreviated = (if $in_sub_dir_of_home {
|
||||
$'~(char separator)($current_dir_relative_to_home)' | str replace -ar '\\' '/'
|
||||
@ -43,7 +43,7 @@ export def current-dir [] {
|
||||
|
||||
# Get repository status as structured data
|
||||
export def repo-structured [] {
|
||||
let in_git_repo = (do --ignore-errors { git rev-parse --abbrev-ref HEAD } | is-empty | nope)
|
||||
let in_git_repo = (do { git rev-parse --abbrev-ref HEAD } | complete | get stdout | is-not-empty)
|
||||
|
||||
let status = (if $in_git_repo {
|
||||
git --no-optional-locks status --porcelain=2 --branch | lines
|
||||
@ -55,8 +55,7 @@ export def repo-structured [] {
|
||||
$status
|
||||
| where ($it | str starts-with '# branch.head')
|
||||
| first
|
||||
| str contains '(detached)'
|
||||
| nope
|
||||
| str contains --not '(detached)'
|
||||
} else {
|
||||
false
|
||||
})
|
||||
@ -86,8 +85,7 @@ export def repo-structured [] {
|
||||
$status
|
||||
| where ($it | str starts-with '# branch.upstream')
|
||||
| str join
|
||||
| is-empty
|
||||
| nope
|
||||
| is-not-empty
|
||||
} else {
|
||||
false
|
||||
})
|
||||
@ -96,8 +94,7 @@ export def repo-structured [] {
|
||||
$status
|
||||
| where ($it | str starts-with '# branch.ab')
|
||||
| str join
|
||||
| is-empty
|
||||
| nope
|
||||
| is-not-empty
|
||||
} else {
|
||||
false
|
||||
})
|
||||
@ -133,8 +130,7 @@ export def repo-structured [] {
|
||||
$status
|
||||
| where ($it | str starts-with '1') or ($it | str starts-with '2')
|
||||
| str join
|
||||
| is-empty
|
||||
| nope
|
||||
| is-not-empty
|
||||
} else {
|
||||
false
|
||||
})
|
||||
@ -143,8 +139,7 @@ export def repo-structured [] {
|
||||
$status
|
||||
| where ($it | str starts-with '?')
|
||||
| str join
|
||||
| is-empty
|
||||
| nope
|
||||
| is-not-empty
|
||||
} else {
|
||||
false
|
||||
})
|
||||
@ -153,8 +148,7 @@ export def repo-structured [] {
|
||||
$status
|
||||
| where ($it | str starts-with 'u')
|
||||
| str join
|
||||
| is-empty
|
||||
| nope
|
||||
| is-not-empty
|
||||
} else {
|
||||
false
|
||||
})
|
||||
@ -380,10 +374,6 @@ export def repo-styled [] {
|
||||
|
||||
# Helper commands to encapsulate style and make everything else more readable
|
||||
|
||||
def nope [] {
|
||||
each { |it| $it == false }
|
||||
}
|
||||
|
||||
def bright-cyan [] {
|
||||
each { |it| $"(ansi -e '96m')($it)(ansi reset)" }
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user