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:
parent
ef5de3ed96
commit
7f8d633ac3
1 changed files with 24 additions and 0 deletions
24
CD-path/cdpath.nu
Normal file
24
CD-path/cdpath.nu
Normal 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)]
|
Loading…
Add table
Add a link
Reference in a new issue