Skip to content

Instantly share code, notes, and snippets.

@grantorchard
Created September 24, 2019 02:23
Show Gist options
  • Save grantorchard/ded67e1f823e96401bcb7e2142de117b to your computer and use it in GitHub Desktop.
Save grantorchard/ded67e1f823e96401bcb7e2142de117b to your computer and use it in GitHub Desktop.
Bash file to import environment variables from 1Password.
#!/bin/bash
# Login to 1Password.
# Assumes you have installed the OP CLI and performed the initial configuration
# For more details see https://support.1password.com/command-line-getting-started/
eval $(op signin my)
# My setup uses a 1Password type of 'Password' and stores all records within a
# single section. The label is the key, and the value is the value.
ev=`op get item "Environment Variables"`
# Convert to base64 for multi-line secrets.
# The schema for the 1Password type 'Password' uses t as the label, and v as the value.
for row in $(echo ${ev} | jq -r -c '.details.sections[1].fields[] | @base64'); do
_envvars() {
echo ${row} | base64 --decode | jq -r ${1}
}
echo "Setting environment variable $(_envvars '.t')"
export $(echo "$(_envvars '.t')=$(_envvars '.v')")
done
@svenlito
Copy link

svenlito commented Jun 7, 2020

sections[1] should be sections[0] 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment