Last active
October 9, 2018 10:49
-
-
Save ffledgling/661524e2951e9fd02c48aa6464db48c3 to your computer and use it in GitHub Desktop.
Custom AWS prompt, configurable with aws instance variables
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
# Custom prompt for debian/ubuntu AWS instances the default is garbage | |
# Works best with dark terminals, tested often with solarized dark | |
# Define colors | |
black="$(tput setaf 0)" | |
red="$(tput setaf 1)" | |
green="$(tput setaf 2)" | |
yellow="$(tput setaf 3)" | |
blue="$(tput setaf 4)" | |
magenta="$(tput setaf 5)" | |
cyan="$(tput setaf 6)" | |
white="$(tput setaf 7)" | |
peach="$(tput setaf 167)" | |
reset="$(tput sgr0)" | |
# Get some nice AWS-y info, assumes awscli is installed | |
AWS_INSTANCE_ID=`curl -s http://169.254.169.254/latest/meta-data/instance-id` | |
EC2_AVAIL_ZONE=`curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone` | |
EC2_REGION="`echo \"$EC2_AVAIL_ZONE\" | sed 's/[a-z]$//'`" | |
# If you configure aws cli, you can use the EC2_NAME as the custom tag | |
#EC2_NAME="$(aws ec2 describe-tags --region $EC2_REGION --filters 'Name=resource-id,Values=$AWS_INSTANCE_ID' 'Name=key,Values=Name' --output text | cut -f5)" | |
_PS1_CUSTOM_TAG="YOUR_TAG" | |
if [[ "$(id -u)" == "0" ]]; | |
then | |
# Root Prompt | |
export PS1='\[$white\]{\[$peach\]$_PS1_CUSTOM_TAG\[$white\]}[\[$red\]\u\[$white\]@\h \W]\# \[$reset\]' | |
else | |
# Regular Prompt | |
export PS1='\[$white\]{\[$peach\]$_PS1_CUSTOM_TAG\[$white\]}[\[$blue\]\u\[$white\]@\h \W]\$ \[$reset\]' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment