when I read a file in Linux with the command 'less' or 'more', how can I get the content in colors?
|
migrated from stackoverflow.com Mar 9 '10 at 10:50
|
You can utilize the power of pygmentize with less - automatically! (No need to pipe by hand.) Write a file ~/.lessfilter
In your .bashrc add
Tested on debian. The idea comes from here Using Pygments with less. |
|||||
|
|
Try the following:
|
|||||||||
|
|
I got the answer in another post: Less and Grep - Color
Warning: Don't put |
|||||||
|
|
|
|||
|
You didn't say what this color should mean, e.g. what should the colors be for a text file? If what you want is syntax highlighting for source code, you need a source code highlighter. I sometimes use pygmentize like this
or
There are other highlighters around. This is pretty fast. If you don't mind firing up
or alternatively see churnd's answer. |
|||
|
|
|
To expand upon captaincomic's answer, you can make it work for most if not all of your scripts that don't have extensions by changing the .lessfilter file around just a bit:
You'd still need to add the two variables to .bashrc:
And you'll still need to make .lessfilter executable:
Also I wanted to add that under debian the pygments package is called python-pygments. I had trouble locating it at first because the obvious misspelling of "pigments" as "pygments" wasn't enough of a hint to me that it was a package that might be prefixed with "python-" by the package manager. |
|||||||
|
|
Using that, you only need to set the following 2 exports in your
|
|||
|
|