Created
April 29, 2026 16:04
-
-
Save miklosbagi/0df1a2e54f4a8d41fea4b0bf978319dd to your computer and use it in GitHub Desktop.
Bitwarden env var exports for bashrc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
🧰 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:
👉 this is a clean, minimal alternative.
🧠 How it works
.envfile: