Skip to content

Commit d382af3

Browse files
authored
Drop added PATHs on folder leave (#1098)
Resolves #1078 Previous behavior: Navigating into a folder with a `Cargo.yml` prepends the target folders to `PATH`. They never get removed. Navigating into different cargo folders one after the other leads to repeated PATH extensions. New behavior: Navigating into a folder with a `Cargo.yml` prepends the target folders to `PATH`. Leaving a folder with a `Cargo.yml` drops the target folders from `PATH`. There is no guarantee that they were added by the script when entering. The PATH could have had the target entries before entering. However, when using this hook, it seems reasonable to assume that this prepend and drop behavior is desired. It also seems reasonable to assume that build target folders would not be used for normal util operations.
1 parent 123cc5f commit d382af3

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

nu-hooks/nu-hooks/rusty-paths/rusty-paths.nu

+15-4
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,24 @@
1313
$env.config = ($env.config | upsert hooks.env_change.PWD {
1414
append {
1515
condition: {|_, after| ($after | path join 'Cargo.lock' | path exists) }
16-
code: {
16+
code: {|_, after|
1717
$env.PATH = (
1818
$env.PATH
19-
| prepend ($env.PWD | path join 'target' 'debug')
20-
| prepend ($env.PWD | path join 'target' 'release')
19+
| prepend ($after | path join 'target' 'debug')
20+
| prepend ($after | path join 'target' 'release')
2121
| uniq
22-
)
22+
)
23+
}
24+
}
25+
| append {
26+
condition: {|before, _| ($before | default '' | path join 'Cargo.lock' | path exists) }
27+
code: {|before, _|
28+
$env.PATH = (
29+
$env.PATH
30+
| where $it != ($before | path join 'target' 'debug')
31+
| where $it != ($before | path join 'target' 'release')
32+
| uniq
33+
)
2334
}
2435
}
2536
})

0 commit comments

Comments
 (0)