Uploading data with 1Password CLI

1Password is one of the best password managers available today. While the iOS, macOS, Windows, and Android clients are obviously the primary clients, they also have a command line tool.

You can automate the upload of files and other secrets to 1Password via the CLI. For instance, here's a script to zip up a directory and upload the contents:

#!/usr/bin/env bash

set -euxo pipefail

FILENAME=secrets.zip
DIR_TO_ZIP=mydir
zip -r $FILENAME $DIR_TO_ZIP

op create document $FILENAME --title="My Secrets File" --vault="Personal"

rm $FILENAME

You can then download the latest secrets file via the CLI with a little help from jq:

#!/usr/bin/env bash

set -euxo pipefail

FILENAME=secrets.zip
DOCUMENT_UUID=$(op list documents --vault="Personal" | jq -r 'sort_by(.updatedAt | fromdateiso8601) | map(select(.overview.title == "My Secrets File" and .trashed == "N")) | [ .[].uuid ] | last')

op get document $DOCUMENT_UUID > $FILENAME

unzip $FILENAME