exenv

Interactive .env generator from example templates with comment guidance, type inference, shell inheritance, and merge safety.

Download as .zip Download as .tar.gz View on GitHub

exenv

Interactive .env generator from example template files with comment guidance, type inference, shell inheritance, and merge safety.


Installation

Via Go

go install github.com/kryft-dev/exenv@latest

Pre-built Binaries

Pre-compiled standalone binaries and archives are available on GitHub Releases:

Agent Skill

Install the official skill for AI coding agents:

npx skills@latest add kryft-dev/exenv

Usage

Interactive Mode

Run in any directory containing a template file (.env.example, .env.sample, .env.template):

exenv

If multiple template candidates exist in subdirectories, an interactive menu will prompt you to choose.

Explicit Source and Output Files

# Positional syntax
exenv .env.example .env.local

# Flag syntax
exenv --source config/.env.template --out config/.env

Non-Interactive & CI/CD

# Accept all defaults; fails if required variables lack defaults
exenv --defaults

# Dry run (renders output to stdout without modifying disk)
exenv --defaults --dry-run

CLI Flags

Flag Short Description Default
--source -s Path to source template file Auto-discovered
--out -o Path to target output file .env
--defaults -d Non-interactive mode using default values false
--force -f Overwrite existing .env without pre-filling false
--yes -y Skip review summary confirmation prompt false
--dry-run   Output generated file to stdout false
--no-env   Do not inherit shell environment variables false
--no-ignore   Do not respect .gitignore during discovery false
--no-backup   Do not create .env.bak on overwrite false
--show-secrets   Display secret values in plain text false
--max-depth   Maximum directory search depth 5
--version -v Display version information  

Template Annotations

Annotate comments directly above variables in .env.example to customize field behaviors:

# Application environment
# @options dev,staging,prod
# @required
APP_ENV=dev

# Stripe secret key
# @secret
STRIPE_API_KEY=

# Public encryption key
# @public
PUBLIC_KEY=""

# Enable experimental background workers
# @bool
ENABLE_WORKERS=false

Key Features

Breadth-First Template Discovery

Searches shallowest directories first, respecting .gitignore rules and automatically skipping standard dependency folders (node_modules, vendor, .venv, dist, build).

Merge Safety & Orphan Preservation

If a target .env exists, current values are pre-filled so existing secrets are not lost. Local custom variables absent from the template are automatically preserved under a dedicated comment section at the bottom.

Shell Environment Inheritance

Matching environment variables already exported in your terminal session are auto-detected and pre-filled with an indicator.

Atomic File Writing

New .env files are created with restricted 0600 permissions (owner read/write only). Overwriting an existing file automatically creates a .env.bak backup copy.


License

Released under the MIT License. Maintained by Kryft.