How to get less or cat to use color in the output from .cat of the .bashrc, similar to vi ‘ing it

catcolorscommand lineless

When I vi my .bashrc file it is colorized, i.e.

enter image description here

but when I cat or less the file I get all white, i.e.

enter image description here

How can I get cat (and less) to have color?

cat does have color for my ruby .rb files but not for these bash dot files the way that vi does for bash dot files.

less doesn't have color for ruby .rb files at all.

Gnome terminal is 3.6.1
Ubuntu is 13.04
Bash is v4.2.45(1)

Best Answer

Trying to run source-highlight as suggested in the linked question produces this error:

$ source-highlight -o STDOUT -i .bashrc --out-format=esc
source-highlight: could not find a language definition for input file .bashrc

That's because .bashrc is not recognized automatically by source-highlight, a quick look through its manual shows that it has the -s flag to set a language, so what you need is:

source-highlight -s bash -o STDOUT -i .bashrc --out-format=esc | less -R