It can be agonizing to pick a good colour scheme for your shell prompt. Especially when you have 256 or more colours to pick from. So rather than waste my time I decided to embrace serendipity and have my shell pick a random colour when it starts. The results are rather pleasing, as you can see below, and if I don’t like a particular colour then it will only last as long as that particular shell.
It also helps to visually distinguish different windows that are being used for different tasks, and root shells are coloured an alarming shade of red. Just pop the following in your .bashrc
.
PS1=${SSH_CLIENT:+$(hostname -s):}'\w \$ ' case "$TERM" in *-256color) if [ "$UID" = 0 ]; then color=196 # Red else color=$((16+(36*(1+RANDOM%5))+(6*(1+RANDOM%5))+(1+RANDOM%5))) fi PS1='\[\033[1m\033[38;5;'$color'm\]'$PS1'\[\033[00m\]' ;; *-color) if [ "$UID" = 0 ]; then color=31 # Red else color=$((31+RANDOM%8)) fi PS1='\[\033[1m\033['$color'm\]'$PS1'\[\033[00m\]' ;; esac unset color
For *-256color
terminals the codes above 36 are a 6x6x6 RGB colour cube. This script avoids darker colours but you can tweak it to your liking. Most modern terminals also support a true colour escape sequence giving full 24-bit colour, but 120 different shades is surely enough for anyone.