[FR] A way to programmatically add a env hook to Nushell #5951
Open
Description
Related problem
Creating this issue to track the conversation we had on Discord. Currently, due to Nushell's functional / immutable design, it's extremely difficult to add a hook to an environment variable programmatically. This is a pain point when writing plugins that actually need those hooks:
- Check if
env.config
exists, or assign an empty hashmap to it - Check if
env.config.hooks
exists, or assign an empty hashmap to it - Check if
env.config.hooks.env_change
exists, or assign an empty hashmap to it - Check if
env.config.hooks.env_change.PWD
exists, or assign an empty array to it - Append the entry to
env.config.hooks.env_change.PWD
and reassign it to the original variable
Even the assignment part is not very easy to do.
Describe the solution you'd like
It would be great if we could make this flow somewhat easier. I don't have suggestions for a specific syntax unfortunately.
Describe alternatives you've considered
No response
Additional context and details
I need it for building zoxide's shell plugin.