4

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)

  • 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. – Michael Durrant Mar 30 '14 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 '14 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. – Michael Durrant Mar 30 '14 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 '14 at 19:41
  • I did not get that error. Text is just white(uncolored). – Michael Durrant Mar 31 '14 at 11:24
8

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
  • +1 great. thanks. how does vi manage to do this without me listing the file this way? – Michael Durrant Mar 30 '14 at 19:41
  • 3
    @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 '14 at 19:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.