Created
September 1, 2020 10:55
-
-
Save jan-swiecki/462f55d1aa04257a3b3181118f0be232 to your computer and use it in GitHub Desktop.
awsenv
This file contains hidden or 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 | |
# Original idea: https://github.com/bartekj/aws-tools | |
awsenv() { | |
IFS=$'\n' | |
for a in "$@"; do | |
[ "$a" == "--save" -o "$a" == "-s" ] && { save_env=1; } || { | |
name="$a" | |
} | |
done | |
name="${name:-default}" | |
source <(gpg2 -d ~/.aws/${name}.asc) | |
if [ -z "$AWS_ACCESS_KEY_ID" ]; then | |
echo "awsenv: failed to load ${name} (no AWS_ACCESS_KEY_ID)" >&2 | |
return 1 | |
fi | |
export AWS_ENV="$name" | |
[ "$save_env" == "1" ] && { | |
echo "Saving '$name' to .awsenv" | |
echo "$name" > .awsenv | |
} | |
unset name | |
#uncomment to update prompt | |
#awsenv_update_prompt | |
} | |
awsenv_update_prompt() { | |
PROMPT_DIRTRIM=2 | |
yellow="\[\033[01;33m\]" | |
end="\[\033[00m\]" | |
PS1='\[\033[01;32m\]\u\[\033[00m\]\[\033[01;33m\][AWS=$AWS_ENV]:\[\033[00m\]\[\033[01;34m\]\w\[\033[00m\]\$ ' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment