Skip to content

Instantly share code, notes, and snippets.

@jeffadams
Last active July 4, 2021 16:05
Show Gist options
  • Save jeffadams/eefd93caafe2a598a94e47e64721c952 to your computer and use it in GitHub Desktop.
Save jeffadams/eefd93caafe2a598a94e47e64721c952 to your computer and use it in GitHub Desktop.
bashrc function for aws prompt
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