direnv-dotenvx


A direnv plugin to load .env or .env.{env} files using dotenvx, with automatic variable detection and shell-safe exports.

Readme

direnv-dotenvx

A simple direnv extension to automatically load environment variables from .env files using dotenvx.

πŸ“¦ Installation

Homebrew

brew install chenasraf/tap/direnv-dotenvx
# or
brew tap chenasraf/tap
brew install direnv-dotenvx

Manual

  1. Clone the repo somewhere:
mkdir -p ~/.config/direnv/lib
git clone https://github.com/chenasraf/direnv-dotenvx ~/.config/direnv/lib/direnv-dotenvx
  1. Symlink or source the loader:
ln -s ~/.config/direnv/lib/direnv-dotenvx/use_dotenvx.sh ~/.config/direnv/lib/use_dotenvx.sh

βœ… This makes the function use_dotenvx available in all .envrc files.

βš™οΈ Usage

In your .envrc:

use_dotenvx              # loads .env or .env.default
use_dotenvx dev          # loads .env.dev

Then run:

direnv allow

πŸ”’ Security Note

⚠️ direnv applies only explicitly exported variables from the .envrc environment. dotenvx handles .env files without needing export statements, so your .env or .env.* files should use the standard KEY=value format. Always review your environment files before allowing direnv to apply them, as they affect your local shell environment.

πŸ“ License

MIT

Contributing

I am developing this package on my free time, so any support, whether code, issues, or just stars is very helpful to sustaining its life. If you are feeling incredibly generous and would like to donate just a small amount to help sustain this project, I would be very very thankful!

Buy Me a Coffee at ko-fi.com

I welcome any issues or pull requests on GitHub. If you find a bug, or would like a new feature, don’t hesitate to open an appropriate issue and I will do my best to reply promptly.