direnv
direnv copied to clipboard
WIP: add unload hook
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'"