direnv: automatically load .env everywhere
β’ 92 words β’ 1 min β’ updated
β οΈ This post is over one year old. It may no longer be up to date or relevant. Opinions may have changed.
Problem statement: Given a monorepo with various scattered .env files, how
to ensure each one of them is automatically loaded when changing directories?
We could create sibling .envrc files in each directory, with the following
content:
shell
#!/bin/sh
dotenvBut this is cumbersome!
Also, perhaps your teammates simply do not want to use direnv.
Here’s a more robust approach:
~/.config/direnv/direnv.toml
toml
[global]
load_dotenv = trueThis ensures every .env file is automatically loaded. No need to splatter
dotenv everywhere!
I have accidentally discovered this is possible via this issue.