1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 22:57:46 +00:00

CD-path implemented in 0.60 (#192)

* finally ported CD-path to 0.60

since there are problems with the scope, i had to used a temp file

* suggestions included
This commit is contained in:
Kamil 2022-04-01 11:35:51 +02:00 committed by GitHub
parent ef5de3ed96
commit 7f8d633ac3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

24
CD-path/cdpath.nu Normal file
View file

@ -0,0 +1,24 @@
def-env c [dir = ""] {
let default = $env.HOME
let complete_dir = if $dir == "" {
$default
} else {
$env.CDPATH
| reduce -f "" { |$it, $acc| if $acc == "" {
let new_path = ([$it $dir] | path join)
if ($new_path | path exists) {
$new_path
} else {
""
}
} else { $acc }}
}
let complete_dir = if $complete_dir == "" { error make {msg: "No such path"} } else { $complete_dir }
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)]