1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 06:37:46 +00:00

update prompts scripts with new str replace syntax (#579)

This commit is contained in:
Darren Schroeder 2023-08-17 18:10:20 -05:00 committed by GitHub
parent dd499c916f
commit 8e086d8771
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 13 deletions

View file

@ -64,13 +64,13 @@ def dir_string [] {
}
let dir = ([
($env.PWD | str substring 0..($home | str length) | str replace --string $home "~"),
($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 separator_color = (if (is-admin) { ansi light_red_bold } else { ansi light_green_bold })
$"($path_color)($dir)(ansi reset)" | str replace --all --string (char path_sep) $"($separator_color)/($path_color)"
$"($path_color)($dir)(ansi reset)" | str replace --all (char path_sep) $"($separator_color)/($path_color)"
}
# Following code cheerfully ~~stolen~~ adapted from:

View file

@ -20,14 +20,14 @@ def home_abbrev [os] {
let is_home_in_path = ($env.PWD | str starts-with $nu.home-path)
if ($is_home_in_path == true) {
if ($os == "Windows") {
let home = ($nu.home-path | str replace -a '\\' '/')
let pwd = ($env.PWD | str replace -a '\\' '/')
let home = ($nu.home-path | str replace -ar '\\' '/')
let pwd = ($env.PWD | str replace -ar '\\' '/')
$pwd | str replace $home '~'
} else {
$env.PWD | str replace $nu.home-path '~'
}
} else {
$env.PWD | str replace -a '\\' '/'
$env.PWD | str replace -ar '\\' '/'
}
}

View file

@ -240,14 +240,14 @@ def home_abbrev [os_name] {
let is_home_in_path = ($env.PWD | str starts-with $nu.home-path)
if $is_home_in_path {
if ($os_name == "windows") {
let home = ($nu.home-path | str replace -a '\\' '/')
let pwd = ($env.PWD | str replace -a '\\' '/')
let home = ($nu.home-path | str replace -ar '\\' '/')
let pwd = ($env.PWD | str replace -ar '\\' '/')
$pwd | str replace $home '~'
} else {
$env.PWD | str replace $nu.home-path '~'
}
} else {
$env.PWD | str replace -a '\\' '/'
$env.PWD | str replace -ar '\\' '/'
}
}

View file

@ -17,8 +17,8 @@ def home_abbrev [os_name] {
let is_home_in_path = ($env.PWD | str starts-with $nu.home-path)
if $is_home_in_path {
if ($os_name =~ "windows") {
let home = ($nu.home-path | str replace -a '\\' '/')
let pwd = ($env.PWD | str replace -a '\\' '/')
let home = ($nu.home-path | str replace -ar '\\' '/')
let pwd = ($env.PWD | str replace -ar '\\' '/')
$pwd | str replace $home '~'
} else {
$env.PWD | str replace $nu.home-path '~'
@ -26,7 +26,7 @@ def home_abbrev [os_name] {
} else {
if ($os_name =~ "windows") {
# remove the C: from the path
$env.PWD | str replace -a '\\' '/' | str substring 2..
$env.PWD | str replace -ar '\\' '/' | str substring 2..
} else {
$env.PWD
}

View file

@ -33,9 +33,9 @@ export def current-dir [] {
let in_sub_dir_of_home = ($current_dir_relative_to_home | is-empty | nope)
let current_dir_abbreviated = (if $in_sub_dir_of_home {
$'~(char separator)($current_dir_relative_to_home)' | str replace -a '\\' '/'
$'~(char separator)($current_dir_relative_to_home)' | str replace -ar '\\' '/'
} else {
$current_dir | str replace -a '\\' '/'
$current_dir | str replace -ar '\\' '/'
})
$'(ansi reset)($current_dir_abbreviated)'