Skip to content

[FR] A way to programmatically add a env hook to Nushell #5951

Open
@ajeetdsouza

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.

Metadata

Assignees

No one assigned

    Labels

    Staleused for marking issues and prs as staleenhancementNew feature or requesthooksHooks are used to react to changes during interactive execution

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions