-
-
Save jared-hughes/e9c5ac666ae3978dd74226effd10e1e3 to your computer and use it in GitHub Desktop.
Rainbow colored bash prompt PS1 string
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
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