1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-07-30 13:47:46 +00:00

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.
This commit is contained in:
Jan Klass 2025-04-22 19:57:11 +02:00 committed by GitHub
parent 123cc5f505
commit d382af3008
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -13,13 +13,24 @@
$env.config = ($env.config | upsert hooks.env_change.PWD {
append {
condition: {|_, after| ($after | path join 'Cargo.lock' | path exists) }
code: {
code: {|_, after|
$env.PATH = (
$env.PATH
| prepend ($env.PWD | path join 'target' 'debug')
| prepend ($env.PWD | path join 'target' 'release')
| prepend ($after | path join 'target' 'debug')
| prepend ($after | path join 'target' 'release')
| uniq
)
)
}
}
| append {
condition: {|before, _| ($before | default '' | path join 'Cargo.lock' | path exists) }
code: {|before, _|
$env.PATH = (
$env.PATH
| where $it != ($before | path join 'target' 'debug')
| where $it != ($before | path join 'target' 'release')
| uniq
)
}
}
})