Created
September 24, 2019 02:23
-
-
Save grantorchard/ded67e1f823e96401bcb7e2142de117b to your computer and use it in GitHub Desktop.
Bash file to import environment variables from 1Password.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sections[1]
should besections[0]
👍