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
Allow disabling direnv from further modifying the environment #1048
base: master
Are you sure you want to change the base?
Conversation
When DIRENV_DISABLE environment variable is set, direnv stops manipulating environment variables. When DIRENV_DISABLE environment variable is unset again, direnv picks up from where it left off and start managing the environment variables again. Keep in mind that setting this variable doesn't unset the variables that direnv has set in the environment, it just toggles direnv, it doesn't roll back all of the effects it has done before the environment variable is set.
I'm open for a cleanup-solution as well, but I'd rather have both a 'dirty' and a 'clean' disable. Also this solution is a way simpler implementation than a full cleanup, and people using it should already be familiar with that caveat. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The solution there might require having to ascend the tree of .direnv files to collect changes, and then running a new shell with Looking at the previous paragraph, that's probably the missing feature: a pushd/popd type function for direnv that tracks a stack of modifications. I'm not a GO person, so I'm not sure whether or not that's trivial, but it could be as simple as caching the location of each .direnv (and any includes in each .direnv) in a cache file descending from the topmost shell process. Thoughts or constructive criticisms? |
direnv definitely does track what changes it's making, that's what is being stored in the |
This would be really nice, I have some nested shells that triggers direnv while it shouldn't so would be nice to set this to opt-out from the direnv hook if I already entered such a shell. |
Same for me, I'm also spawning some nested shells where I don't want direnv to continue loading. Right now I've modified the hook to deal with this:
This works for the nested shell use-case, but if I disable it, I cannot enable it in the nested shell later on (although I specifically don't want to do that for my use-case). It would be great if this could be a native feature of direnv though, otherwise I'd have to get my colleagues use my custom hook wrapping instead of using the hook direnv spits out by default. |
Stumbled on this when looking for a solution to disable direnv. Would love for this to get merge since it seems ready @reegnz 🙏 |
When DIRENV_DISABLE environment variable is set, direnv stops manipulating environment variables. When DIRENV_DISABLE environment variable is unset again, direnv picks up from where it left off and start managing the environment variables again.
Keep in mind that setting this variable doesn't unset the variables that direnv has set in the environment, it just toggles direnv, it doesn't roll back all of the effects it has done before the environment variable is set.
Fixes #550