Last active
December 2, 2021 06:56
-
-
Save petrabarus/794f291dbf4468c91e636cff56291d2c to your computer and use it in GitHub Desktop.
1Password to Environment Variables
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
#!/usr/bin/env bash | |
# Load environment variables from 1password | |
# To execute this script, execute the command below. | |
# source 1passwordtoenv.sh 'Name of the item' | |
ITEM_NAME=$1 | |
# Signin | |
eval $(op signin) | |
# Load environment variables | |
SECRETS=`op get item "${ITEM_NAME}"` | |
ENV_VARS=$(echo $SECRETS | jq -r '[.details.sections[] as $in | $in.fields[] as $h | $in | del(.fields) as $in2 | $h * $in2][] | select(.t != "") | "\(.t)=\(.v)"') | |
for ENV_VAR in $ENV_VARS; do | |
export $(echo $ENV_VAR) | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment