Friday, May 3, 2024
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 1950  / 2 Years ago, mon, august 8, 2022, 12:50:10

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?


More From » command-line

 Answers
4

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
}

[#28230] Monday, August 8, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
inciplyies

Total Points: 10
Total Questions: 114
Total Answers: 93

Location: French Polynesia
Member since Sun, Dec 20, 2020
3 Years ago
;