Skip to content

Instantly share code, notes, and snippets.

@epcim
Created September 18, 2026 14:12
Show Gist options
  • Select an option

  • Save epcim/48b3426b306bbcc6f45799b9fff633bb to your computer and use it in GitHub Desktop.

Select an option

Save epcim/48b3426b306bbcc6f45799b9fff633bb to your computer and use it in GitHub Desktop.
export gopass, to bitwarden civ
#!/bin/bash -e
# THE SIMPLE SPARTA WAY, BE CAREFULL
# UPDATE stores/root as per your needs
# 1. Define paths (Change these if your paths are non-default)
STORE_DIR="$HOME/.local/share/gopass/stores/root" # Check ~/.password-store if not here
AGE_KEY="$HOME/.config/gopass/age/identities" # Your private age identity key
age -d -o $AGE_KEY.temp $AGE_KEY || exit 1
export AGE_KEY=$AGE_KEY.temp
# 2. Setup the Bitwarden CSV structure
CSV_FILE="$PWD/bitwarden_import.csv"
# folder,favorite,type,name,notes,fields,reprompt,login_uri,login_username,login_password,login_totp
echo "folder,name,username,password,login_uri,notes" >| "$CSV_FILE"
# 3. Recursively find and decrypt nested secrets
cd "$STORE_DIR" || exit 1
pwd
find . -type f -name "*.age" | sed 's|^\./||' | while read -r relative_path; do
# Extract the full folder tree and secret name
# e.g., "Work/Production/Database.age" -> folder="Work/Production", name="Database"
clean_path="${relative_path%.age}"
folder=$(dirname "$clean_path")
name=$(basename "$clean_path")
[ "$folder" = "." ] && folder=""
# Decrypt using age directly to avoid gopass CLI looping hang-ups
echo age -d -i "$AGE_KEY" "$relative_path"
raw_content=$(age -d -i "$AGE_KEY" "$relative_path")
# Parse standard pass fields
password=$(echo "$raw_content" | head -n 1 | sed 's/"/""/g')
username=$(echo "$raw_content" | grep -i "^username:" | cut -d' ' -f2- | sed 's/"/""/g')
url=$(echo "$raw_content" | grep -i "^url:" | cut -d' ' -f2- | sed 's/"/""/g')
# Bundle remaining lines into notes
notes=$(echo "$raw_content" | tail -n +2 | grep -v -i -E "^(username|url):" | tr '\n' ' ' | sed 's/"/""/g')
# Append safely enclosed in quotes to handle special characters
echo PARSED
echo "\"$folder\",\"$name\",\"$username\",\"$password\",\"$url\",\"$notes\""
echo TOFILE
echo "\"$folder\",\"$name\",\"$username\",\"$password\",\"$url\",\"$notes\"" >> "$CSV_FILE"
done
echo "Done!
echo ""
echo "IMPORTANT:"
echo "- Manually remove: $AGE_KEY"
echo "- Export CSV from: $CSV_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment