A lightweight environment management utility for running commands with environment-specific configurations.
env-run allows you to manage multiple environment configurations (dev, uat, prod) and execute commands with the appropriate environment variables loaded. It supports layered configuration with base settings and environment-specific overrides.
- Multi-environment support: Separate configurations for dev, uat, and prod
- Layered configuration: Base settings with environment-specific overrides
- Secret management: Integration with Linux
secret-toolfor secure credential storage - Two usage modes: Command execution and environment sourcing
- XDG compliance: Uses
$XDG_CONFIG_HOMEor falls back to~/.config
- Copy
env-runto your~/bindirectory or anywhere in your$PATH - Make it executable:
chmod +x env-run - Run the setup script to create initial environment files:
./setup-envs-template.sh
Run commands with environment-specific variables:
env-run dev npm start
env-run prod ./deploy.sh
env-run uat python manage.py migrateLoad environment variables into your current shell:
source <(env-run dev --export)
source <(env-run prod --export)Environment files are stored in ~/.config/env/:
base.env- Variables shared across all environmentsdev.env- Development-specific variablesuat.env- UAT/staging-specific variablesprod.env- Production-specific variables
base.env:
API_BASE_URL=https://api.example.com
LOG_LEVEL=infodev.env:
ASPNETCORE_ENVIRONMENT=Development
API_BASE_URL=https://dev-api.example.com
LOG_LEVEL=debugThe utility integrates with Linux's secret-tool for secure credential storage:
secret-tool store --label='API Key Dev' service env-vars key API_KEY_DEVAPI_KEY=$(secret-tool lookup service env-vars key API_KEY_DEV 2>/dev/null || echo "fallback-value")secret-tool search service env-varsRun the test suites to verify functionality:
Test the main env-run utility:
./test-env-run.shTest the setup script:
./test-setup-envs.shThe test scripts verify:
- env-run tests: Error handling, environment loading, variable overrides, export functionality, command execution
- setup-envs tests: Directory creation, file generation, content validation, XDG compliance, secret-tool detection
- Bash shell
secret-tool(optional, for secret management)- Install on Ubuntu/Debian:
sudo apt install libsecret-tools
- Install on Ubuntu/Debian:
This project is provided as-is for personal and commercial use.