diff --git a/crates/nu-std/lib/mod.nu b/crates/nu-std/lib/mod.nu index 42b036438..b262e99af 100644 --- a/crates/nu-std/lib/mod.nu +++ b/crates/nu-std/lib/mod.nu @@ -38,14 +38,17 @@ export def-env "path add" [ --append (-a) # append to $env.PATH instead of prepending to. ...paths # the paths to add to $env.PATH. ] { - let-env PATH = ( - $env.PATH - | if $append { append $paths } - else { prepend $paths } - ) + let path_name = if "PATH" in $env { "PATH" } else { "Path" } + let-env $path_name = ( + $env + | get $path_name + | if $append { append $paths } + else { prepend $paths } + ) + if $ret { - $env.PATH + $env | get $path_name } } diff --git a/crates/nu-std/tests/test_std.nu b/crates/nu-std/tests/test_std.nu index fe5b8e733..9a7c1452f 100644 --- a/crates/nu-std/tests/test_std.nu +++ b/crates/nu-std/tests/test_std.nu @@ -3,23 +3,27 @@ use std export def test_path_add [] { use std "assert equal" - with-env [PATH []] { - assert equal $env.PATH [] + let path_name = if "PATH" in $env { "PATH" } else { "Path" } + + with-env [$path_name []] { + def get_path [] { $env | get $path_name } + + assert equal (get_path) [] std path add "/foo/" - assert equal $env.PATH ["/foo/"] + assert equal (get_path) ["/foo/"] std path add "/bar/" "/baz/" - assert equal $env.PATH ["/bar/", "/baz/", "/foo/"] + assert equal (get_path) ["/bar/", "/baz/", "/foo/"] - let-env PATH = [] + let-env $path_name = [] std path add "foo" std path add "bar" "baz" --append - assert equal $env.PATH ["foo", "bar", "baz"] + assert equal (get_path) ["foo", "bar", "baz"] assert equal (std path add "fooooo" --ret) ["fooooo", "foo", "bar", "baz"] - assert equal $env.PATH ["fooooo", "foo", "bar", "baz"] + assert equal (get_path) ["fooooo", "foo", "bar", "baz"] } }