Index

Working with colors

echo

printing in color
RED='\033[0;31m'
YELLOW='\033[0;33m'
PLAIN='\033[0m'

echo "$red fatal error! $PLAIN"

ls

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

less

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

grep

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
modifiers
1 make bright (usually just bold)
21 stop bright (normalizes boldness)
4 underline
24 stop underline
0 clear all formatting
more
http://www.lihaoyi.com/post/BuildyourownCommandLinewithANSIescapecodes.html
https://misc.flogisoft.com/bash/tip_colors_and_formatting