Skip to content

Instantly share code, notes, and snippets.

@chadfennell
Created December 9, 2021 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chadfennell/73d1bfee6898f498b6902bc477a9a711 to your computer and use it in GitHub Desktop.
Save chadfennell/73d1bfee6898f498b6902bc477a9a711 to your computer and use it in GitHub Desktop.
Load ENV Variables from 1Password
#!/bin/bash
# 1) Create a Secure Note
# 2) Add a section titled "ENV" (or pick your own title but adjust the script below)
# 3) Add a Password Field (repeat this as many times as you like)
# 4) Replace "password" with your export field name (e.g. AWS_S3_KEY_ID)
# 5) Set the value of the field (e.g. the actual AWS key id)
# 6) tag the item with "exports" (or pick your own tag but adjust the script below)
# The 1Password tag applied to items with env configurations
TAG="exports"
# The section within an item that contains env variables
SECTION="env"
echo " \nLoading Environemental Variables (and printing them out for reference):\n"
op list items --vault "Shared with BinaryNoggin" \
| jq ".[] | select(.overview.tags | .[]? == \"$TAG\" ) | .uuid" \
| xargs -I {} op get item {} \
| jq ".details.sections[] | select(.title | match(\"$SECTION\";\"i\"))" \
| jq -r '.fields[]? | [.t,.v] | @tsv' |
while IFS=$'\t' read -r field value ; do
echo "export $field=$value"
declare -g "$field"="$value"
export $field
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment