Last active
July 4, 2021 16:05
-
-
Save jeffadams/eefd93caafe2a598a94e47e64721c952 to your computer and use it in GitHub Desktop.
bashrc function for aws prompt
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
aws () { | |
aws_cmd=`command which aws` | |
if [[ $@ =~ 'help' ]] | |
then | |
command $aws_cmd $@ | |
return | |
fi | |
identity=`$aws_cmd sts get-caller-identity` || return | |
account=`echo $identity | jq '.Account' | tr -d '"'` | |
arn=`echo $identity | jq '.Arn' | tr -d '"'` | |
user=`echo $arn | awk -F ":" '{ print $6 }'` | |
if [[ $user =~ assumed-role* ]] ; then | |
S="_" | |
else | |
S="/" | |
fi | |
username=`echo $user | awk -F $S '{ print $2 }'` | |
export PS1="$username@$account # " | |
command $aws_cmd $@ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment