Skip to content

Instantly share code, notes, and snippets.

@dwallraff
Last active September 28, 2018 11:24
Show Gist options
  • Save dwallraff/2f7aa41d0424bf06d4c0d83642e84d0f to your computer and use it in GitHub Desktop.
Save dwallraff/2f7aa41d0424bf06d4c0d83642e84d0f to your computer and use it in GitHub Desktop.
Export all non-trashed docs from 1Password
#! /usr/bin/env bash
## Copy all docs from 1password
mkdir files || exit
# Get all current (non-trashed) doc UUIDs and titles
# shellcheck disable=2016
op list documents | jq -r '. as $in | keys[] | select($in[.].trashed=="N") as $res | [$in[$res].uuid, $in[$res].overview.title] | @json' > files/docs_list
# Loop over list and save each one off
TOTAL="$(wc -l < files/docs_list)"
for ((i=1; i<="$TOTAL"; i++))
do
FILENAME=""
UUID=""
let COUNT=$i-1
UUID=$(jq -rs '.['"$COUNT"'][0]' < files/docs_list)
FILENAME=$(op get item "$UUID" | jq -r '.details.documentAttributes.fileName')
if [ -z "$FILENAME" ]; then
FILENAME=$(jq -rs '.['"$COUNT"'][1]' < docs_list)
fi
echo "Getting doc $i of $TOTAL: $FILENAME ($UUID)..."
op get document "$UUID" > files/"$FILENAME"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment