-
Notifications
You must be signed in to change notification settings - Fork 209
/
cdpath.nu
36 lines (32 loc) · 1.05 KB
/
cdpath.nu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def-env c [dir = ""] {
let default = if $nu.os-info.name == "windows" {
$env.USERPROFILE
} else {
$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 --unspanned {msg: "No such path"}
} else if (($complete_dir | path expand | path type) != "dir") {
error make --unspanned {msg: "Not a directory"}
} else {
($complete_dir | path expand)
}
cd $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)]
# WINDOWS:
# let-env CDPATH = ["", $env.USERPROFILE, ([$env.USERPROFILE, "AppData\\Roaming\\"] | path join)]