A shell utility to list, read, set, and delete variables in your ~/profile/.env — the single source of truth for all shell environment variables.
Changes take effect immediately in the current shell — no need to restart or re-source manually.
Add envm as a shell function so it runs in your current shell context (required for live export/unset to work):
# In ~/profile/.aliases_utils or ~/.zshrc / ~/.bashrc:
envm() {
local ENV_FILE="${PROFILE_DIR:-$HOME/profile}/.env"
# ... (see envm script file for full function body)
}Or source the provided script directly:
# ~/.zshrc or ~/.bashrc
source ~/bin/envm-fn # if saved as a function fileNote: If run as a plain script (
~/bin/envm),exportandunsetonly affect the subprocess — changes won't be live in your current shell. Define it as a function instead.
Set PROFILE_DIR to override the default location:
export PROFILE_DIR=/path/to/your/profileenvm — list all variables
envm KEY — show value of KEY
envm KEY value — set KEY=value (prompts to confirm if already exists)
envm -d KEY — delete KEY (prompts to confirm)
# List all env vars
$ envm
/home/user/profile/.env
GH_TOKEN ghp_xxxxxxxxxxxx
OLLAMA_API_BASE http://127.0.0.1:11434
JAVA_HOME /usr/share
# Read a single value
$ envm OLLAMA_API_BASE
OLLAMA_API_BASE=http://127.0.0.1:11434
# Add a new variable (live in current shell immediately)
$ envm MY_API_KEY abc123
Added: MY_API_KEY=abc123
$ echo $MY_API_KEY
abc123
# Update an existing variable
$ envm GH_TOKEN ghp_newtoken
Current: GH_TOKEN=ghp_oldtoken
Replace with 'ghp_newtoken'? [y/N] y
Updated: GH_TOKEN=ghp_newtoken
# Delete a variable
$ envm -d MY_API_KEY
Delete MY_API_KEY=abc123
Confirm? [y/N] y
Deleted: MY_API_KEY- Reads use
grepon the.envfile — no shell state required - Writes use
sed -ifor in-place editing - After any write,
.envissourced and the var is live immediately (when run as a shell function) - Deletes call
unsetin addition to removing the line from the file - Variables are stored as
export KEY=valuelines, compatible with any POSIX shell