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:
parent
123cc5f505
commit
d382af3008
1 changed files with 15 additions and 4 deletions
|
@ -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
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue