Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: add unload hook #1262

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

skogsbrus
Copy link

This is a WIP proposal for adding an unload behavior to direnv, as discussed in #129. Mostly intended as a conversation starter on how this should be implemented instead.

This implementation is very hacky:

  • Allows circumvention of 'direnv allow', since the unload hook can source another script which can be modified without 'direnv allow' being required to run
  • Does not introduce any new abstraction for user-provided hooks; instead relies on the hook command being exported as an env variable and then evaluated
  • Defining long unload hooks is cumbersome without sourcing another script
  • Seems to also be executed on 'direnv deny', which I guess makes sense

Sample output:

johanan@airm2 (add-unload-hook) ~/code/direnv cd foo                                      ~/code/direnv
direnv: loading ~/code/direnv/foo/.envrc
johanan@airm2 (add-unload-hook) ~/code/direnv/foo cat .envrc                          ~/code/direnv/foo
export DIRENV_UNLOAD="echo 'Execute unload hook'"
johanan@airm2 (add-unload-hook) ~/code/direnv/foo cd ..                               ~/code/direnv/foo
direnv: unloading
Execute unload hook

.envrc samples:

export DIRENV_UNLOAD="source .unloadrc"
export DIRENV_UNLOAD="echo 'Executing unload hook'"

This is a WIP proposal for adding an unload behavior to direnv. Mostly
intended as a conversation starter on how this should be implemented
instead.

This implementation is very hacky:

- allows circumvention of 'direnv allow', since the unload hook can
  source another script which can be modified without 'direnv allow'
  being required to run
- does not introduce any new abstraction for user-provided hooks;
  instead relies on the hook command being exported as an env variable
  and then evaluated
- Defining long unload hooks is cumbersome without sourcing another
  script
- Is executed on 'direnv deny'
- Probably missing some cleanup of the DIRENV_UNLOAD env variable

Sample output:

```
johanan@airm2 (add-unload-hook) ~/code/direnv cd foo                                      ~/code/direnv
direnv: loading ~/code/direnv/foo/.envrc
johanan@airm2 (add-unload-hook) ~/code/direnv/foo cat .envrc                          ~/code/direnv/foo
export DIRENV_UNLOAD="echo 'Execute unload hook'"
johanan@airm2 (add-unload-hook) ~/code/direnv/foo cd ..                               ~/code/direnv/foo
direnv: unloading
Execute unload hook
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant