Skip to content

Instantly share code, notes, and snippets.

@miklosbagi
Created April 29, 2026 16:04
Show Gist options
  • Select an option

  • Save miklosbagi/0df1a2e54f4a8d41fea4b0bf978319dd to your computer and use it in GitHub Desktop.

Select an option

Save miklosbagi/0df1a2e54f4a8d41fea4b0bf978319dd to your computer and use it in GitHub Desktop.
Bitwarden env var exports for bashrc
# create bitwarden session
bw_session() {
if [ -z "$BW_SESSION" ] || ! bw status --session "$BW_SESSION" | jq -e '.status == "unlocked"' >/dev/null; then
export BW_SESSION="$(bw unlock --raw)"
fi
}
# bitwarden exports from secure note
bw_export_note_env() {
local item="$1"
local line key value
bw_session
bw sync
while IFS= read -r line; do
# trim leading/trailing whitespace
line="$(printf '%s' "$line" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
# skip empty lines
[[ -z "$line" ]] && continue
# skip comments / headings
[[ "$line" =~ ^# ]] && continue
# only accept KEY=value
[[ "$line" != *=* ]] && continue
key="${line%%=*}"
value="${line#*=}"
key="$(printf '%s' "$key" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
value="$(printf '%s' "$value" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')"
# only allow sane env var names
[[ "$key" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]] || continue
export "$key=$value"
done < <(
bw get item "$item" --session "$BW_SESSION" | jq -r '.notes'
)
}
# bitwarden export the note
# example find item id: bw list items --search "My Secure Note" | jq -r '.[] | "\(.id) \(.name)"'
bw_export_note_env 18C0FC6B-702D-4A1E-9C4D-0075368202E4
@miklosbagi

Copy link
Copy Markdown
Author

🧰 Bitwarden (Vaultwarden) → Environment Variables (Simple, Local Dev Setup)

This is a lightweight shell-based solution to load secrets from Bitwarden/Vaultwarden into environment variables — without needing a full secrets manager like Vault, Doppler, or Infisical.

🎯 Purpose

Most existing tools for this (envwarden, bwenv, bitwarden-env, etc.) are no longer maintained or have moved to paid/hosted solutions.

If you:

  • use Vaultwarden (self-hosted Bitwarden)
  • want a simple, transparent setup
  • don’t want to introduce heavy infra (Vault, etc.)
  • just need local dev secrets

👉 this is a clean, minimal alternative.


🧠 How it works

  • Store secrets in a Bitwarden Secure Note
  • Format it like a .env file:
### Github
GH_TOKEN=bleh

# derived
GITHUB_TOKEN=$GH_TOKEN

### Database
DB_HOST=localhost
DB_PASSWORD=secret

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment