A minimal, standalone .env and .envrc loader with no dependencies.
Well, I'll be honest - use direnv if you can. It's a great tool and I use it myself. I built this because I had an absolute headache trying to get direnv working on a windows machine. It was likely a very specific problem due to a locked down machine. (And profile being on onedrive which was set by a group policy). So 🤷 this is what I came up with.
- Zero dependencies
- Cross-platform support (Windows, Linux, macOS)
- Supports both
.env
and.envrc
files - Simple shell integration
brew tap willwade/envloader https://github.com/willwade/envloader
brew install willwade/envloader/envloader
scoop bucket add envloader https://github.com/willwade/envloader
scoop install envloader
Due to how shell environments work, the way you use envloader depends on your shell:
# Either:
Invoke-Expression $(envloader)
# Or:
. envloader
# Either:
eval "$(envloader)"
# Or:
source envloader
This will:
- Find the nearest
.env
or.envrc
file - Load its environment variables into your current shell session
- Variables will be available to all processes run in that shell session
Advanced options:
# Load from a specific file
envloader -f path/to/.env
# Search up to specific depth for .env files
envloader --depth 3
For a more convenient experience, you can add a shell function to your profile:
Add to your $PROFILE
(eg. notepad $PROFILE
):
function envload {
# Join multiple lines into a single string and pipe to Invoke-Expression
envloader | Out-String | Invoke-Expression
}
Add to your ~/.bashrc
:
envload() {
eval "$(envloader)"
}
Add to your ~/.zshrc
:
envload() {
eval "$(envloader)"
}
Add to your ~/.config/fish/functions/envload.fish
:
function envload
eval (envloader)
end
After adding to your profile and restarting your shell, you can simply use:
envload
This will load environment variables from the nearest .env
or .envrc
file.
The envloader
binary:
- Finds and reads
.env
/.envrc
files - Outputs shell-appropriate commands for evaluation
- Variables are set in your shell when commands are evaluated
Requires Go 1.x or higher and goreleaser to be installed.
git clone https://github.com/willwade/envloader
cd envloader
goreleaser build --snapshot --skip-publish
Note: To use the GitHub releases, you'll need to set up a GITHUB_TOKEN
with appropriate permissions if you're downloading from private repositories.