3

The source-highlight package is installed on my system. It highlights files I view with less using /usr/bin/lesspipe and LESSOPEN environment variable.

Now, I want to change the color scheme this mechanism uses for some/all filetypes. I have root on the machine. How do I do this?

Note: It's a Devuan 3 Beowulf (~= Debian 10 Buster) Linux distribution.

2 Answers 2

2

Well, you can use a different style file in the source-highlight that's used for less. In /usr/share/source-highlight/src-hilite-lesspipe.sh, you will find:

source-highlight --failsafe --infer-lang -f esc --style-file=esc.style -i "$source" ;;

you can replace esc.style with a different style file (from usr/share/source-highlight/). However... most style files aren't compatible with emitting ANSI escape codes, and won't work. So, you're basically stuck.

Try contacting the author perhaps.

Haven't found anything relevant in the GNU source-highlight manual.

1

The esc default is really bad (version 3.1.8), especially for black terminals because function names are printed as black.

I've spent months trying to figure this out and finally found a good solution. Modify /usr/share/source-highlight/src-hilite-lesspipe.sh to use the esc256 built-in style which has bolder colors:

source-highlight --failsafe --infer-lang -f esc256 --style-file=esc256.style -i "$source" ;;

You can tweak the colors in your own style file, but I found the esc -> esc256 change a big step forward for C++ code that I regularly view in the terminal with less.

For selective detection you could use the lesspipe script to detect filetype, then presumably use options like -s, --src-lang=STRING to launch source-highlight with a different language style.

2
  • Well, that doesn't really let me customize the scheme, it's just an adjustment of a single, non-customized scheme.
    – einpoklum
    Commented Mar 18, 2023 at 10:33
  • On my ubuntu installation, the default style files were placed in /usr/share/source-highlight/. From there you can copy/paste to a new file and modify. source-highlight --style-file=/path/to/custom.style --input=<input-file> will format a file with your new style. Commented Mar 20, 2023 at 5:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .