4

I have installed python-pygments and using it for syntax highlighting with less as described by mankoff here I put a function in my .bashrc

    cless ()
    {
        pygmentize -f terminal "$1" | less -R
    }

it is enabling syntax highlighting with less. But when I am going to open a file like /etc/fstab or /etc/apt/apt.conf a error saying

Error: no lexer for filename '/etc/apt/apt.conf' found

I found option to show pygmentize the lexer with -l at this manpage. But what will be the appropriate lexer for such files? and how to use it?

3

Buried in pygmentize --help:

If -g is passed, attempt to guess the lexer from the file contents, or pass through as plain text if this fails (this can work for stdin).

Simply change your code to:

cless () {
    pygmentize -gf terminal "$1" | less -R
}
0

To have syntax highlight on Ubuntu/Debian first install

apt install source-highlight

Then you may wan't to add this two environment variables to ~/.bashrc

export LESSOPEN="| /usr/bin/src-hilite-lesspipe.sh %s"
export LESS=' -R '

Also notice v on less open the file on default editor (defined by select-editor command) that might have SH. Here how to add compatibility to a lot of files in nano.

Reference

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.