diff --git a/CD-path/cdpath.nu b/filesystem/cdpath.nu similarity index 67% rename from CD-path/cdpath.nu rename to filesystem/cdpath.nu index b271ff5..61e8162 100644 --- a/CD-path/cdpath.nu +++ b/filesystem/cdpath.nu @@ -5,7 +5,6 @@ def-env c [dir = ""] { $default } else { $env.CDPATH - | path expand | reduce -f "" { |$it, $acc| if $acc == "" { let new_path = ([$it $dir] | path join) if ($new_path | path exists) { @@ -15,11 +14,17 @@ def-env c [dir = ""] { } } 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 } # You need to have $env.CDPATH variable declared, my suggestion from config.nu: -# let-env CDPATH = [".", $env.HOME, "/", ([$env.HOME, ".config"] | path join)] +# let-env CDPATH = [".", $env.HOME, "/", ([$env.HOME, ".config"] | path join)] \ No newline at end of file