1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-02 15:17:47 +00:00

cdpath.nu moved and improved (#245)

Now you can move only to an actual dir, relative paths and symlinks now work just fine, too
This commit is contained in:
Kamil 2022-06-04 15:00:35 +02:00 committed by GitHub
parent 0f9d10d78d
commit 5c10a37f46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,7 +5,6 @@ def-env c [dir = ""] {
$default $default
} else { } else {
$env.CDPATH $env.CDPATH
| path expand
| reduce -f "" { |$it, $acc| if $acc == "" { | reduce -f "" { |$it, $acc| if $acc == "" {
let new_path = ([$it $dir] | path join) let new_path = ([$it $dir] | path join)
if ($new_path | path exists) { if ($new_path | path exists) {
@ -16,7 +15,13 @@ def-env c [dir = ""] {
} else { $acc }} } else { $acc }}
} }
let complete_dir = if $complete_dir == "" { error make {msg: "No such path"} } else { $complete_dir } let complete_dir = if $complete_dir == "" {
error make {msg: "No such path"}
} else if (($complete_dir | path expand | path type) != "dir") {
error make {msg: "Not a directory"}
} else {
($complete_dir | path expand)
}
let-env PWD = $complete_dir let-env PWD = $complete_dir
} }