I am using pygments to do source highlighting on the command line. I created an alias for lessh, so less that does source code highlighting. Sure, I could use a text editor like nano or vim, but I don't want there to be a chance that I'll edit the source file.
Bash Shell
I use a dark terminal environment, which works for "native" style. Choose whichever style you prefer.
This uses the less environment variable LESSOPEN to pre-process the input file(s):
alias lessh='LESSOPEN="| pygmentize -f 256 -O style=native %s" less -M -R '
Default style version:
alias lessh='LESSOPEN="| pygmentize %s" less -M -R '
You could set the LESSOPEN variable globally and use less, but this will pipe every single file through pygmentize. That will make less run slower because it will always run files through pygmentize.
Fish Shell
The fish shell equivalents is to create functions, funced lessh is used to create the function. Test it out. Then, save it to the fish shell with the funcsave lessh.
function lessh
LESSOPEN="| pygmentize -f 256 -O style=native %s" less -M -R $argv
end
Note: I also made cath, which is basically alias cath="pygmentize". Which doesn't really work like cat, so it does not concatenate the files and highlight. It just outputs a file to the screen highlighted. I should choose a different alias for this.
I thought someone else might be able to benefit from this. Could this be added to the documentation as a way to use pygments? (GNU Source-highlight documented a something similar, which I was inspired by.)
I am using pygments to do source highlighting on the command line. I created an alias for lessh, so less that does source code highlighting. Sure, I could use a text editor like nano or vim, but I don't want there to be a chance that I'll edit the source file.
Bash Shell
I use a dark terminal environment, which works for "native" style. Choose whichever style you prefer.
This uses the
lessenvironment variableLESSOPENto pre-process the input file(s):Default style version:
You could set the
LESSOPENvariable globally and useless, but this will pipe every single file throughpygmentize. That will makelessrun slower because it will always run files throughpygmentize.Fish Shell
The fish shell equivalents is to create functions,
funced lesshis used to create the function. Test it out. Then, save it to the fish shell with thefuncsave lessh.Note: I also made
cath, which is basicallyalias cath="pygmentize". Which doesn't really work likecat, so it does not concatenate the files and highlight. It just outputs a file to the screen highlighted. I should choose a different alias for this.I thought someone else might be able to benefit from this. Could this be added to the documentation as a way to use pygments? (GNU Source-highlight documented a something similar, which I was inspired by.)