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

Feature: ability to specify a list of ignored environment variables #401

Open
Arkham opened this issue Oct 4, 2018 · 5 comments · May be fixed by #889
Open

Feature: ability to specify a list of ignored environment variables #401

Arkham opened this issue Oct 4, 2018 · 5 comments · May be fixed by #889

Comments

@Arkham
Copy link

Arkham commented Oct 4, 2018

Hello there, first of all thanks for building direnv!

Recently I was bitten by the fact that direnv controls the environment variables that TMUX uses for bookkeeping. Luckily I was able to get the source and see that we are already ignoring some special environment variables in https://github.com/direnv/direnv/blob/master/env_diff.go so I just had to add

if strings.HasPrefix(key, "TMUX") {
	return true
}

run make and have my setup working again.

Do you think it would be a good idea to be able to pass a list of ignored variables/patterns? Let me know and I can work on building a PR for this.

@zimbatm
Copy link
Member

zimbatm commented Oct 4, 2018

Hi @Arkham ,

have you seen this page yet? https://github.com/direnv/direnv/wiki/Tmux

I don't know if adding an exception is a good idea or not. I would like to avoid adding specialized exceptions like that in direnv but if it solves the problem then maybe. Tmux seems to be changing a bunch of environment variables on start which is tricky to deal with from direnv's perspective. I think the issue is really with Tmux but last time I tried digging in the code I got lost.

Have a look at the wiki page to see if it can solve your problem. If you get a better understanding of Tmux than I do I am open to add that exception.

@Arkham
Copy link
Author

Arkham commented Oct 8, 2018

Hey @zimbatm, thanks for getting back to me. Yup, I've seen that page and it was very useful to get tmux to work: the specific issue that I ran into was that tmux uses a special environment variable to track which is the current active pane ($TMUX_PANE) and direnv was interfering with that environment variable because I had ran direnv reload inside a tmux pane.

But in more general terms, I think that there are use cases when the user might want to ignore specific environment variables. By looking at the source of env_diff we already have escape hatches for fish and bash; recently a colleague of mine asked me if there is a way to tell direnv to completely ignore SSH_AUTH_SOCK so it made me think that there are more cases out there of people needing escape hatches for direnv.

@zimbatm
Copy link
Member

zimbatm commented Oct 9, 2018

I would be open to have that configurable in the config.toml file. Something like [env] ignore_keys = ["TMUX_PANE", "SSH_AUTH_SOCK"]. It would require a bit of change in the code to pass the configuration object around.

@spacefrogg
Copy link

@Arkham See also restrict direnv load on how you can ignore environment variables with the current direnv implementation.

tmatilai added a commit to tmatilai/direnv that referenced this issue Jan 22, 2022
Add `[env] / ignore_keys` configuration to ignore the listed environment
variables, in addition to the default ones.

Fixes direnv#401
@tmatilai tmatilai linked a pull request Jan 22, 2022 that will close this issue
@indigoviolet
Copy link

Another example of needing an escape hatch:

I use zsh as my interactive shell, but prefer bash scripts for portability. I configure $PS4 separately for zsh and bash, but every direnv load ends up overriding my zsh PS4 with my bash PS4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

4 participants