Skip to content

Instantly share code, notes, and snippets.

Created October 7, 2012 01:13
What would you like to do?
### Random terminal colors
# Assign _PS1, _PS2, and _PS3 arrays
# Orange
'\[\e[38;5;208m\] \w $(__git_ps1 "\[\e[38;5;166m\]%s ")\[\e[38;5;202m\]❱ \[\e[0m\]'
# Blue
'\[\e[38;5;45m\] \w $(__git_ps1 "\[\e[38;5;39m\]%s ")\[\e[38;5;33m\]❱ \[\e[0m\]'
# Green
'\[\e[38;5;46m\] \w $(__git_ps1 "\[\e[38;5;34m\]%s ")\[\e[38;5;28m\]❱ \[\e[0m\]'
# Yellow
'\[\e[38;5;226m\] \w $(__git_ps1 "\[\e[38;5;220m\]%s ")\[\e[38;5;214m\]❱ \[\e[0m\]'
# Orange
'\[\e[38;5;202m\] ❱ \[\e[0m\]'
# Blue
'\[\e[38;5;33m\] ❱ \[\e[0m\]'
# Green
'\[\e[38;5;28m\] ❱ \[\e[0m\]'
# Yellow
'\[\e[38;5;214m\] ❱ \[\e[0m\]'
# Orange
' \e[38;5;202m▎ \e[0m'
# Blue
' \e[38;5;33m▎ \e[38;5;231m'
# Green
' \e[38;5;28m▎ \e[38;5;231m'
# Yellow
' \e[38;5;214m▎ \e[38;5;231m'
# Set PS1, PS2, and PS3 to a random selection.
random_terminal_color() {
local length=`expr ${#_PS1[@]} - 1`
# Make sure none of the colors are used twice in a row
if [[ $_TERMINAL_COLOR ]]; then
local rand=-1
until [ $rand != $_TERMINAL_COLOR -a $rand -gt -1 ]; do
local rand=$((RANDOM%$length+1))
#local rand=`shuf -i 0-$length -n1`
export _TERMINAL_COLOR=$rand
export _TERMINAL_COLOR=$((RANDOM%$length))
#export _TERMINAL_COLOR=`shuf -i 0-$length -n1`
export PS1="${_PS1[$_TERMINAL_COLOR]}"
export PS2="${_PS2[$_TERMINAL_COLOR]}"
export PS4="${_PS4[$_TERMINAL_COLOR]}"
terminal_stuff() {
if [[ $_JUST_OPENED = true ]]; then
clear_terminal() {
# Emulate the terminal just being opened, so we don't append a newline.
tput clear
# Alias clear to our clear_terminal function
alias clear=`echo clear_terminal`
# Use a new color every time, and run any custom stuff.
export PROMPT_COMMAND="random_terminal_color; terminal_stuff"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment