Skip to content

Instantly share code, notes, and snippets.

@jared-hughes
Forked from duckythescientist/lololps1.bash
Last active June 1, 2022 11:42
Show Gist options
  • Save jared-hughes/e9c5ac666ae3978dd74226effd10e1e3 to your computer and use it in GitHub Desktop.
Save jared-hughes/e9c5ac666ae3978dd74226effd10e1e3 to your computer and use it in GitHub Desktop.
Rainbow colored bash prompt PS1 string
lolps1() {
PREV_EXIT_CODE=$?
# PS1 rainbow modified from https://gist.github.com/duckythescientist/8338f028e018fd3fecae58e4f1c45def
# Replace $HOME with ~
mypwd=${PWD/#$HOME/"~"}
# Make a persistent, incrementing seed to make a smooth rainbow effect from line to line
if [ -z ${LOLCAT_SEED+x} ]; then LOLCAT_SEED=1; else let "LOLCAT_SEED += 1"; fi
PS1=$(echo " $mypwd" | lolcat --force --freq 0.3 --seed $LOLCAT_SEED 2>/dev/null)
# Strip the "reset colors to normal" commands
PS1=$(echo "$PS1" | sed $'s/\033\[0m//g')
# Replace escape sequences with [escaped escape sequences]
# e.g.: \[\033[38;5;39m\]
PS1=$(echo "$PS1" | sed -r $'s/\033''(\[[0-9]+;[0-9]+;[0-9]+m)/\\\[\\033\1\\\]/g')
# change the color back to white and add the $/# PS1 character
PS1="${PS1}\[\033[0m\]\$ "
# Prepend status indicator (based on https://twitter.com/lunasorcery/status/1433555199952519168)
PS1="\[\033[0;$[91+($PREV_EXIT_CODE==0)]m\]●\[\033[0m\]"$PS1
}
PROMPT_COMMAND=lolps1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment