Skip to content

Instantly share code, notes, and snippets.

@joemaller
Last active March 9, 2018 21:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joemaller/4503986 to your computer and use it in GitHub Desktop.
Save joemaller/4503986 to your computer and use it in GitHub Desktop.
A set of simple color functions to help customize the shell's $PS1 prompt. These wrap the nasty color and background escape codes into more humane functions. Due to shell string escaping oddness, these must be used with `PROMPT_COMMAND` instead of directly in PS1. A complete git-aware .bashrc prompt is here: https://gist.github.com/joemaller/f7d…
# https://gist.github.com/joemaller/4503986
#
# A set of color functions to help with fancy $PS1 prompts
#
# This:
# PROMPT_COMMAND='PS1="\e[32;1m\]\u@\[\e[35;1m\]\H \[\e[0m\]\w]\$ "''
#
# Can be more clearly written as:
# PROMPT_COMMAND='PS1="$(DARK_GREEN \\u@)$(PURPLE \\H) \w]\$ "''
#
# note: Escape codes returned from these functions will not work in a directly
# assigned $PS1, use PROMPT_COMMAND to prevent extra escaping.
#
# Text Colors
function RED { echo "\[\e[0;91m\]$1\[\e[0m\]"; }
function DARK_RED { echo "\[\e[0;31m\]$1\[\e[0m\]"; }
function YELLOW { echo "\[\e[0;93m\]$1\[\e[0m\]"; }
function DARK_YELLOW { echo "\[\e[0;33m\]$1\[\e[0m\]"; }
function GREEN { echo "\[\e[0;92m\]$1\[\e[0m\]"; }
function DARK_GREEN { echo "\[\e[0;32m\]$1\[\e[0m\]"; }
function CYAN { echo "\[\e[0;96m\]$1\[\e[0m\]"; }
function DARK_CYAN { echo "\[\e[0;36m\]$1\[\e[0m\]"; }
function BLUE { echo "\[\e[0;94m\]$1\[\e[0m\]"; }
function DARK_BLUE { echo "\[\e[0;34m\]$1\[\e[0m\]"; }
function MAGENTA { echo "\[\e[0;95m\]$1\[\e[0m\]"; }
function PURPLE { echo "\[\e[0;35m\]$1\[\e[0m\]"; }
function BLACK { echo "\[\e[0;30m\]$1\[\e[0m\]"; }
function GRAY { echo "\[\e[0;90m\]$1\[\e[0m\]"; }
function LIGHT_GRAY { echo "\[\e[0;37m\]$1\[\e[0m\]"; }
function WHITE { echo "\[\e[0;97m\]$1\[\e[0m\]"; }
# Black on Background Color
function B_ON_RED { echo "\[\e[0;30;101m\]$1\[\e[0m\]"; }
function B_ON_DARK_RED { echo "\[\e[0;30;41m\]$1\[\e[0m\]"; }
function B_ON_YELLOW { echo "\[\e[0;30;103m\]$1\[\e[0m\]"; }
function B_ON_DARK_YELLOW { echo "\[\e[0;30;43m\]$1\[\e[0m\]"; }
function B_ON_GREEN { echo "\[\e[0;30;102m\]$1\[\e[0m\]"; }
function B_ON_DARK_GREEN { echo "\[\e[0;30;42m\]$1\[\e[0m\]"; }
function B_ON_CYAN { echo "\[\e[0;30;106m\]$1\[\e[0m\]"; }
function B_ON_DARK_CYAN { echo "\[\e[0;30;46m\]$1\[\e[0m\]"; }
function B_ON_BLUE { echo "\[\e[0;30;104m\]$1\[\e[0m\]"; }
function B_ON_DARK_BLUE { echo "\[\e[0;30;44m\]$1\[\e[0m\]"; }
function B_ON_MAGENTA { echo "\[\e[0;30;105m\]$1\[\e[0m\]"; }
function B_ON_PURPLE { echo "\[\e[0;30;45m\]$1\[\e[0m\]"; }
function B_ON_BLACK { echo "\[\e[0;30;40m\]$1\[\e[0m\]"; }
function B_ON_DARK_GRAY { echo "\[\e[0;30;100m\]$1\[\e[0m\]"; }
function B_ON_GRAY { echo "\[\e[0;30;47m\]$1\[\e[0m\]"; }
function B_ON_LIGHT_GRAY { echo "\[\e[0;30;107m\]$1\[\e[0m\]"; }
# White on Background Color
function W_ON_RED { echo "\[\e[0;97;101m\]$1\[\e[0m\]"; }
function W_ON_DARK_RED { echo "\[\e[0;97;41m\]$1\[\e[0m\]"; }
function W_ON_YELLOW { echo "\[\e[0;97;103m\]$1\[\e[0m\]"; }
function W_ON_DARK_YELLOW { echo "\[\e[0;97;43m\]$1\[\e[0m\]"; }
function W_ON_GREEN { echo "\[\e[0;97;102m\]$1\[\e[0m\]"; }
function W_ON_DARK_GREEN { echo "\[\e[0;97;42m\]$1\[\e[0m\]"; }
function W_ON_CYAN { echo "\[\e[0;97;106m\]$1\[\e[0m\]"; }
function W_ON_DARK_CYAN { echo "\[\e[0;97;46m\]$1\[\e[0m\]"; }
function W_ON_BLUE { echo "\[\e[0;97;104m\]$1\[\e[0m\]"; }
function W_ON_DARK_BLUE { echo "\[\e[0;97;44m\]$1\[\e[0m\]"; }
function W_ON_MAGENTA { echo "\[\e[0;97;105m\]$1\[\e[0m\]"; }
function W_ON_PURPLE { echo "\[\e[0;97;45m\]$1\[\e[0m\]"; }
function W_ON_BLACK { echo "\[\e[0;97;40m\]$1\[\e[0m\]"; }
function W_ON_DARK_GRAY { echo "\[\e[0;97;100m\]$1\[\e[0m\]"; }
function W_ON_GRAY { echo "\[\e[0;97;47m\]$1\[\e[0m\]"; }
function W_ON_LIGHT_GRAY { echo "\[\e[0;97;107m\]$1\[\e[0m\]"; }
@justinatcamfil
Copy link

Great idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment