Skip to content

Instantly share code, notes, and snippets.

@paulcarey
Created July 27, 2009 12:44
Show Gist options
  • Save paulcarey/156199 to your computer and use it in GitHub Desktop.
Save paulcarey/156199 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Use the HOST_ENV variable to set the prompt color so the environment
# is obvious at the prompt
# Add it to .bashrc and optionally /etc/skel/.bashrc
function setprompt {
# Format is ESC[Value;...;Valuem
# For example, for bold red text on black background \[\033[1;31;40m\]
# Reference at http://ascii-table.com/ansi-escape-sequences.php
BOLD="\[\033[1m\]"
RED="\[\e[31m\]"
YELLOW="\[\e[33m\]"
GREEN="\[\e[32m\]"
BLUE="\[\e[34m\]"
MAGENTA="\[\e[35m\]"
CYAN="\[\e[36m\]"
WHITE="\[\e[37m\]"
OFF="\[\033[m\]"
case $HOST_ENV in
"prod" )
PROMPT_COLOR=$RED
;;
"staging" )
PROMPT_COLOR=$YELLOW
;;
"test" )
PROMPT_COLOR=$WHITE
;;
"dev" )
PROMPT_COLOR=$CYAN
;;
* )
PROMPT_COLOR=$CYAN
export HOST_ENV=scratch
esac
PS1="${PROMPT_COLOR}\u@${HOST_ENV}:\W${OFF} \$ "
}
PROMPT_COMMAND=setprompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment