Working with colors


printing in color

echo "$red fatal error! $PLAIN"


ls normally strips color for anything but console
ls / > no.txt
to get ls write color escape sequences to output other than console
ls --color=yes / > yes.txt
cat can print color if the file has the color escape sequences
cat yes.txt


Have less show forwarded colors
ls --color=yes | less -R


grep show original colors
ls / --color=yes | grep "lib" --color=no
grep write color escape sequences of match to output other than console
ls / | grep --color=yes lib > yes.txt
pass ansi color codes to less
ls / | grep --color=yes lib | less -R

syntax highlighting programming files

pygmentize [file]
or if the lexer is not obvious from the file extension
pygmentize -l [lexer] [file]

creating color coded html

Convert console output to html with color codes processed appropriately
ls / --color=yes | aha
for black background rather than white
ls / --color=yes | aha --black
ANSI codes foreground:
30 black
31 red
32 green
33 yellow
34 blue
35 magenta
36 cyan
37 white
ANSI codes background:
40 black background
41 red background
42 green background
43 yellow background
44 blue background
45 magenta background
46 cyan background
47 white background
1 make bright (usually just bold)
21 stop bright (normalizes boldness)
4 underline
24 stop underline
0 clear all formatting