Compress $HOME into ~ in prompt (#8173)

This commit is contained in:
Alex Saveau 2023-02-22 14:36:26 -08:00 committed by GitHub
parent 0e86ba4b63
commit aba0fb0000
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,10 +1,16 @@
# Nushell Environment Config File
def create_left_prompt [] {
let home = ($env | get -i (if $nu.os-info.name == "windows" { "USERPROFILE" } else { "HOME" }) | into string)
let dir = ([
($env.PWD | str substring 0..($home | str length) | str replace -s $home "~"),
($env.PWD | str substring ($home | str length)..)
] | str join)
let path_segment = if (is-admin) {
$"(ansi red_bold)($env.PWD)"
$"(ansi red_bold)($dir)"
} else {
$"(ansi green_bold)($env.PWD)"
$"(ansi green_bold)($dir)"
}
$path_segment