-
Notifications
You must be signed in to change notification settings - Fork 621
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
Add automatic .env
load
#845
Conversation
This should be ready to review. |
Mainly because it has a better compatibility with P10k. For now, it does not read `.env` files automatically, but will probably do in the future: direnv/direnv#845
I am not a maintainer but I read throught the changes (especially the tests) and it looks very reasonable to me. |
Thanks for your PR. I should have left a note before; before I can merge this, I want to give it a try and see how it feels. |
Whoa, what a good day to live! Thank you! |
As now direnv/direnv#845 was merged and we finally have first-class support for .env files. The move to chezmoiexternal was due to 2 things: because I want the new version fast and because I make it indenpendent of the OS, allowing it to be used on devcontainers as well.
As much as I like this addition I would like to disable this by default if there is a way to do so. Is there? |
You can disable it by creating an .envrc file right beside your .env file. Even if it's empty. |
Can this be disabled without requiring a .envrc file? I'm now getting prompts to allow loading any .env files on my machine, even in places that are completely unrelated to anything I want running under direnv. I tried creating an empty .envrc file in my user directory just to see if that would override it in all subdirectories, but it still wants to load any .env files in the current directory, which is understandable given the file search behavior, but it is in this case unfortunate. |
@felipecrs: but even if you create an empty I use |
Not with the current implementation. But I also agree that it would be nice to be configurable.
Indeed, this is the current behavior. That's why I said: You can disable it by creating an .envrc file right beside your .env file.
Variables removed? That's a weird, I don't think I understood, but you may try to create an |
Yes, I understand that. However, that now requires me to litter my machine with empty .envrc files anywhere I have a .env file. And in fact, I have more .env files on my machine that I don't want direnv to load than those that I do (currently using an explicit dotenv_if_exists). |
Right, so let's focus on making it configurable then. I would suggest you to first open a new issue so it can be discussed with the maintainers. |
Hello @felipecrs,
resp:
And I now have quite some projects where I created files named |
@mfriedenhagen if I understood well, all you have to do is to create an empty .envrc right beside your .env files, as I suggested first. |
Hi @felipecrs, that I tried firstly. I touched .envrc and allowed the empty file. Changing out of the project directory immediately exported e.g. LAB_CORE_HOST. But when I cd'd to the project directory with now both .env and .envrc again, the variable disappears from the environment as before. |
Wow, okay... that was not supposed to be how direnv works. Unless I'm wrong, direnv keeps collecting the environment for all the .envrc files up to your home, so the blank .envrc file should not make it stop doing that. But I'm not as experienced in direnv as some other guys here, so... can someone confirm if what I said correct? /cc @zimbatm |
I've found this feature has completely broken direnv for the way I use it. A few projects I work on have different components (in sub-folders, e.g. frontend and backend) that each need their own component-specific environmental variables. I use direnv to populate project-wide settings that I need in the shell (e.g. AWS credentials) and also setup the development environment (e.g. initialising nvm). Then I use .env files with dotenv (or something similar) to automatically load them in the development environment when the app is booted - but I don't care about accessing the contents of the .env files in the shell. |
Ok guys, I created #880. Would that address your concerns? |
The feature to automatically load .env files in #845 is nice, but it's a little too greedy in certain situations. Allow skipping that behavior by default (going back to explicit dotenv calls in .envrc files) in the configuration toml file. Co-authored-by: zimbatm <zimbatm@zimbatm.com>
Follow-up on direnv#845 and direnv#911: resolves direnv#916 This commit simply updates the error messages and documentation to more accurately reflect the current opt-in configurable handling of `.env` files.
This PR is a continuation of #438, made by @aude.