4

I'm using gnu source-highlight mostly with less (so it's using ANSII terminal codes to make colours). However, with a dark background colour, the highlighted parts are dim and hard to read.

Is there an easy way to tell source-highlight to use a colour scheme more suited to a dark background (as can be done with, for example, vim)?

drevicko
  • 14,382
  • 15
  • 75
  • 97
  • I suspect it may be possible to setup `LESSOPEN` to pipe stuff through the `vim` highlighter.. – drevicko Oct 22 '12 at 23:02
  • Looks like vim can be used like less: http://superuser.com/a/168284/101005 – drevicko Oct 22 '12 at 23:13
  • The best option for me was [using pygmentize](http://unix.stackexchange.com/questions/19439/how-can-i-display-syntax-highlighting-on-a-file/19440#19440) – ricab Jun 19 '13 at 12:39
  • 1
    I put this in a bash initialization file `pygless() { LESSOPEN="| pygmentize -f terminal256 -O style=native -g %s" less "$@" }` and I now use _pygless_ to read code :) – ricab Jun 19 '13 at 13:15
  • 1
    nice one @ricab. Had to change it a bit: `pygless() { LESSOPEN="| pygmentize -f terminal256 -O style=native -g %s"; less "$@"; }` (note the semicolons). Make it an answer and I'll accept it (: – drevicko Jun 19 '13 at 23:58
  • right @drevicko, I missed the semicolon! Still, only the last one should be there, because I want to use the value of LESSOPEN for the less command. Otherwise, an export would be needed (see [this](http://stackoverflow.com/a/10856211/563765)) – ricab Jun 20 '13 at 09:02
  • indeed! strange, I thought it'd worked before with the extra `;` - perhaps I'd exported it or some such?? who knows! ;) – drevicko Jun 21 '13 at 01:47
  • Don't know, perhaps you had it already globally set. Also, notice the "-R" that I had forgotten. Cheers – ricab Jun 21 '13 at 10:38

1 Answers1

4

I don't know how to do this with source-highlight, so I skipped it altogether and used pygmentize to the same end. For that, I make a function that I use instead of less when I want code highlighting

pygless()
{
  LESSOPEN="| pygmentize -f terminal256 -O style=native -g %s" less -R "$@";
}
Community
  • 1
  • 1
ricab
  • 2,697
  • 4
  • 23
  • 28
  • (in 2019) `pygmentize` is unfortunately very slow: `⯈time pygmentize -f terminal256 -O style=native -g < /usr/include/linux/fs.h` 0,39s user 0,03s system 99% cpu 0,428 total `⯈time source-highlight -i /usr/include/linux/fs.h -f esc256` 0,03s user 0,00s system 98% cpu 0,037 total edit: ok, so SO comment formatting is still stuck in the 90s – pythonator Nov 07 '19 at 10:43