mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 22:57:46 +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:
parent
0f9d10d78d
commit
5c10a37f46
1 changed files with 9 additions and 4 deletions
|
@ -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)]
|
Loading…
Add table
Add a link
Reference in a new issue