I use .env environment variable files in every project. Docker Compose supports .env files. And now direnv supports them too. direnv is a cli tool that detects a .envrc or .env file and runs source .env automatically for you when you cd into a project directory.
-
Install Homebrew.
-
Install
direnv.brew install direnv -
Follow these instructions to add the direnv hook to your shell.
-
Create a direnv config directory.
mkdir -p ~/.config/direnv -
Copy this snippet telling direnv to load
.envfiles in addition to the default.envrcfiles.[global] load_dotenv=true -
Create a direnv config file.
pbpaste > ~/.config/direnv/direnv.toml -
Restart your Terminal, and
.envfiles will load automatically.