5

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)

7
  • I had tried this previously with unix.stackexchange.com/questions/100841/how-can-i-colorize-cat-output-including-unknown-filetypes-in-bw?rq=1 but that isn't working now. Not sure why. Mar 30, 2014 at 19:14
  • Please always include the actual error you get, "it fails" with no explanation is not very useful. In this case, the error explains the problem precisely and would have saved all of us some time.
    – terdon
    Mar 30, 2014 at 19:25
  • Sure. I thought " When I vi my .bashrc file it is colorized, but when I cat or less the file I get all white,How can I get cat (and less) to have color?" was all I needed. Mar 30, 2014 at 19:40
  • Yes, but that is already answered nicely in the linked question. Since you linked to it, I am assuming you tried that and got the error in my answer. That's what I mean, in the future please include the errors you get.
    – terdon
    Mar 30, 2014 at 19:41
  • I did not get that error. Text is just white(uncolored). Mar 31, 2014 at 11:24

1 Answer 1

9

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
2
  • +1 great. thanks. how does vi manage to do this without me listing the file this way? Mar 30, 2014 at 19:41
  • 4
    @MichaelDurrant vi has it's own syntax definition rules and can detect bash syntax better apparently. They are completely separate programs, no reason to expect them to work in the same way.
    – terdon
    Mar 30, 2014 at 19:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .