Created
April 26, 2019 12:53
-
-
Save mcarlton00/564d456373d2537adcacb3bb3fd7da96 to your computer and use it in GitHub Desktop.
Export AWS Credentials to your local environment from Lastpass
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
############################################### | |
# Assumes you have AWS API credentials saved in the "notes" section of a LastPass entry | |
# Notes: | |
# AWS_ACCESS_KEY_ID=$KEY_ID | |
# AWS_SECRET_ACCESS_KEY=$KEY | |
# AWS_DEFAULT_REGION=us-east-1 | |
# | |
# Optionally will include the Lastpass entry name in your zsh prompt | |
############################################### | |
# Place in your `.zshrc` and use to pull AWS credentials into your local shell session | |
# Usage: | |
# lp-env 'Entry Name' | |
function lp-env () { | |
local raw_creds=`lpass show --notes "$1"` | |
if [[ "$raw_creds" ]]; then | |
local export_cmd=`echo $raw_creds | sed -z 's/^/export /; s/\n/ /g'` | |
eval "$export_cmd" | |
export LPASS_ENV_ACCOUNT="--$1" | |
fi | |
} | |
# To include the entry name in your zsh prompt, | |
# include `%F{red}${LPASS_ENV_ACCOUNT}${LPASS_ENV_ACCOUNT:+ }%f` in your prompt setup. | |
# Full Example: | |
setprompt () { | |
setopt prompt_subst | |
RPROMPT='' | |
PROMPT=' | |
$PR_IMPOSTER%D{%a %h %e, %l:%M} | %/ %F{red}${LPASS_ENV_ACCOUNT}${LPASS_ENV_ACCOUNT:+ }%f | |
%m%# ' | |
PS2='' | |
} | |
# Results: https://imgur.com/a/OAQLYER |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment