mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 14:40:06 +02:00
expand paths and split PATH in std path add
(#10710)
related to - https://discord.com/channels/601130461678272522/614593951969574961/1162406310155923626 # Description this PR - does a bit of minor refactoring - makes sure the input paths get expanded - makes sure the input PATH gets split on ":" - adds a test - fixes the other tests # User-Facing Changes should give a better overall experience with `std path add` # Tests + Formatting adds a new test case to the `path_add` test and fixes the others. # After Submitting
This commit is contained in:
@ -40,7 +40,7 @@ export def --env "path add" [
|
||||
...paths # the paths to add to $env.PATH.
|
||||
] {
|
||||
let span = (metadata $paths).span
|
||||
let paths = ($paths | flatten)
|
||||
let paths = $paths | flatten
|
||||
|
||||
if ($paths | is-empty) or ($paths | length) == 0 {
|
||||
error make {msg: "Empty input", label: {
|
||||
@ -52,13 +52,14 @@ export def --env "path add" [
|
||||
|
||||
let path_name = if "PATH" in $env { "PATH" } else { "Path" }
|
||||
|
||||
let paths = ($paths | each {|p|
|
||||
if ($p | describe) == "string" {
|
||||
$p
|
||||
} else if ($p | describe | str starts-with "record") {
|
||||
$p | get -i $nu.os-info.name
|
||||
let paths = $paths | each {|p|
|
||||
let p = match ($p | describe | str replace --regex '<.*' '') {
|
||||
"string" => $p,
|
||||
"record" => { $p | get --ignore-errors $nu.os-info.name },
|
||||
}
|
||||
})
|
||||
|
||||
$p | path expand
|
||||
}
|
||||
|
||||
if null in $paths or ($paths | is-empty) {
|
||||
error make {msg: "Empty input", label: {
|
||||
@ -70,9 +71,10 @@ export def --env "path add" [
|
||||
|
||||
load-env {$path_name: (
|
||||
$env
|
||||
| get $path_name
|
||||
| if $append { append $paths }
|
||||
else { prepend $paths }
|
||||
| get $path_name
|
||||
| split row (char esep)
|
||||
| path expand
|
||||
| if $append { append $paths } else { prepend $paths }
|
||||
)}
|
||||
|
||||
if $ret {
|
||||
|
Reference in New Issue
Block a user