Saturday, August 25, 2012

Colors in bash

Bash is capable of generating a huge spectrum of colors for text. Here is a small code in shell script which generates all the 256 different colors bash can render:
for i in {0..255}; do printf "\x1b[38;5;${i}mCLR-${i}\t"; done; echo; reset;

The last echo is for printing a blank like after the output, without that the command prompt would appear at the end of the output. More import is reset present at the end, without which your terminal might not go back to the original settings.

In case you are wondering how to print colored output in terminal, please read:
Now you have a number to color mapping which you can use to specify your favorite color in config files of various command like applications like vi and tmux.