Skip to content

Instantly share code, notes, and snippets.

@joshjdevl
Forked from shawnburke/gist:3750709
Last active August 29, 2015 14:02
Show Gist options
  • Save joshjdevl/26ddf5f5e8d9e495c87b to your computer and use it in GitHub Desktop.
Save joshjdevl/26ddf5f5e8d9e495c87b to your computer and use it in GitHub Desktop.
ubuntu ec2 bash prompt instance tag name
# these make the ec2 commands just work
export AWS_ACCESS_KEY=[AWS access key]
export AWS_SECRET_KEY=[AWS secret]
# fetch the instance id
export INSTANCE_ID=$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-id)
#grep out the tag you're looking for, in this case "Name"
export APP_TAG=$(ec2dtag --region us-west-2 --filter "key=Name" --filter "resource-type=instance" --filter "resource-id=$INSTANCE_ID" | grep -oE "Name\\W+(.+)$" | grep -oE "\\W.+$")
#trim beginning and leading whitespace
export APP_TAG=$(echo $APP_TAG | sed -e 's/^ *//' -e 's/ *$//')
#put it into the prompt
export PS1="\u@$APP_TAG:\w>"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment