mirror of
https://github.com/nushell/nu_scripts.git
synced 2024-08-17 09:20:28 +03:00
fix regressions noted in 0.93.1 from 0.83: (#843)
1. double pathsep when displaying PWD 2. error 'not a git repo' when PWD outside a repo (`do --ignore-error {}` no longer eats the stderr text?) 3. improve display when terminal quite narrow (not a regression, just an improvement) 4. reduce overhead for padding
This commit is contained in:
parent
407a313bbb
commit
429126f3d8
2
.gitignore
vendored
2
.gitignore
vendored
@ -4,3 +4,5 @@
|
|||||||
.mailmap
|
.mailmap
|
||||||
|
|
||||||
check-files.nu
|
check-files.nu
|
||||||
|
|
||||||
|
.vscode/
|
||||||
|
@ -37,22 +37,21 @@ export def main [
|
|||||||
if 'VIRTUAL_ENV_PROMPT' in $env {'(' + $env.VIRTUAL_ENV_PROMPT + ') '}
|
if 'VIRTUAL_ENV_PROMPT' in $env {'(' + $env.VIRTUAL_ENV_PROMPT + ') '}
|
||||||
)($pad_char + $pad_char + $pad_char)(current_exe)")
|
)($pad_char + $pad_char + $pad_char)(current_exe)")
|
||||||
let left_content_len = ($left_content | ansi strip | str length -g)
|
let left_content_len = ($left_content | ansi strip | str length -g)
|
||||||
|
|
||||||
let mid_content = ($" (dir_string) ")
|
let mid_content = ($" (dir_string) ")
|
||||||
let mid_content_len = ($mid_content | ansi strip | str length -g)
|
let mid_content_len = ($mid_content | ansi strip | str length -g)
|
||||||
|
|
||||||
let term_width = ((term size) | get columns)
|
|
||||||
let left_padding = ((($term_width / 2) - ($mid_content_len / 2)) | into int)
|
|
||||||
|
|
||||||
let dirs_segment = $" |(dirs show | each {|it| if $it.active {'V'} else {'.'}} | str join '')|"
|
let dirs_segment = $" |(dirs show | each {|it| if $it.active {'V'} else {'.'}} | str join '')|"
|
||||||
let right_content = ($"(repo-styled)($pad_char + $pad_char + $pad_char)($dirs_segment)")
|
let right_content = ($"(repo-styled)($pad_char + $pad_char + $pad_char)($dirs_segment)")
|
||||||
let right_content_len = ($right_content | ansi strip | str length -g)
|
let right_content_len = ($right_content | ansi strip | str length -g)
|
||||||
|
|
||||||
let right_padding = (($term_width - $left_padding - $mid_content_len) | into int)
|
let term_width = ((term size) | get columns)
|
||||||
|
let mid_padding = ($term_width - $left_content_len - $right_content_len)
|
||||||
|
|
||||||
[(ansi reset),
|
[(ansi reset),
|
||||||
($left_content | fill --character $pad_char --width $left_padding --alignment left),
|
$left_content,
|
||||||
$mid_content,
|
($mid_content | fill --character $pad_char --width $mid_padding --alignment center),
|
||||||
($right_content | fill --character $pad_char --width $right_padding --alignment right),
|
$right_content,
|
||||||
"\n"
|
"\n"
|
||||||
] | str join ''
|
] | str join ''
|
||||||
}
|
}
|
||||||
@ -71,25 +70,12 @@ def current_exe [] {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# build current working directory segment
|
# build current working directory segment
|
||||||
|
## don't get sucked into the path syntax wars: simply color portions of path to flag priviliged vs normal user mode.
|
||||||
def dir_string [] {
|
def dir_string [] {
|
||||||
|
|
||||||
mut home = ""
|
|
||||||
try {
|
|
||||||
if $nu.os-info.name == "windows" {
|
|
||||||
$home = $env.USERPROFILE
|
|
||||||
} else {
|
|
||||||
$home = $env.HOME
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let dir = ([
|
|
||||||
($env.PWD | str substring 0..($home | str length) | str replace $home "~"),
|
|
||||||
($env.PWD | str substring ($home | str length)..)
|
|
||||||
] | str join)
|
|
||||||
|
|
||||||
let path_color = (if (is-admin) { ansi red_bold } else { ansi green_bold })
|
let path_color = (if (is-admin) { ansi red_bold } else { ansi green_bold })
|
||||||
let separator_color = (if (is-admin) { ansi light_red_bold } else { ansi light_green_bold })
|
let separator_color = (if (is-admin) { ansi light_red_bold } else { ansi light_green_bold })
|
||||||
$"($path_color)($dir)(ansi reset)" | str replace --all (char path_sep) $"($separator_color)/($path_color)"
|
$"($path_color)($env.PWD)(ansi reset)" | str replace --all (char path_sep) $"($separator_color)(char path_sep)($path_color)"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Following code cheerfully ~~stolen~~ adapted from:
|
# Following code cheerfully ~~stolen~~ adapted from:
|
||||||
@ -97,7 +83,7 @@ def dir_string [] {
|
|||||||
|
|
||||||
# Get repository status as structured data
|
# Get repository status as structured data
|
||||||
def repo-structured [] {
|
def repo-structured [] {
|
||||||
let in_git_repo = (do --ignore-errors { git rev-parse --abbrev-ref HEAD } | is-empty | nope)
|
let in_git_repo = ((git rev-parse HEAD err> /dev/null | complete | get exit_code) == 0)
|
||||||
|
|
||||||
let status = (if $in_git_repo {
|
let status = (if $in_git_repo {
|
||||||
git --no-optional-locks status --porcelain=2 --branch | lines
|
git --no-optional-locks status --porcelain=2 --branch | lines
|
||||||
|
Loading…
Reference in New Issue
Block a user