Skip to content

Instantly share code, notes, and snippets.

@mohamedadaly
Last active May 14, 2022 14:52
Show Gist options
  • Save mohamedadaly/8f578ca375c173dcdb52771a9404577b to your computer and use it in GitHub Desktop.
Save mohamedadaly/8f578ca375c173dcdb52771a9404577b to your computer and use it in GitHub Desktop.
# Export data from Bitwarden to import into KeePass 2
# Logic:
# - list folders and items and cat them together into two objects
# - add the two objects into one with . | add with .items and .folders
# - loop on items with .items[] as $i
# - for each $i, loop on folders with .folders and select the right folder
# with that id (basically a left join)
# - generate the object with required fields
# - create a comma separated line from each object, including the header at the beginning
# - output the csv file to x.csv
# Operation:
# -----------
# Log into bw
# bw login
# run this script
# import x.csv into KeePass2
# delete x.csv
(bw list folders | jq '{folders: .}' ; bw list items | jq '{items: .}') | cat | \
jq -s '[. | add |
.items[] as $i |
(.folders[] | select($i.folderId == .id)) as $f |
{
title: $i.name,
username: select($i.login != null) | $i.login.username,
password: select($i.login != null) | $i.login.password,
url: [ select($i.login != null) | select($i.login.uris != null) | $i.login.uris[].uri ] | join(","),
notes: $i.notes,
group: $f.name,
fields: [ select($i.fields != null) | $i.fields[].name + ": " + $i.fields[].value ] | join("\n")
}]' | \
jq -r '(.[0] | keys_unsorted | @csv), (.[] | map(.) | @csv)' > x.csv
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment