2021-05-26 07:48:08 -07:00
2021-02-11 11:27:58 -08:00
2021-02-11 11:27:58 -08:00
2021-02-11 11:27:58 -08:00
2021-02-11 11:27:58 -08:00
2021-02-11 11:27:58 -08:00

Syntax highlighter for less

Uses Pygments to provide syntax highlighting for supported file types. The .lessfilter is generated by parsing the Pygments documentation website. screenshot

Installation

1. Install Pygments & gawk

Ensure that you have the latest version of Pygments installed by using pip, as your distro's packaged version is likely outdated. You'll also need gawk.

# remove any installed packaged versions
sudo apt autoremove python-pygments python3-pygments

# install latest version
sudo pip install Pygments --upgrade

# install gawk
sudo apt install gawk

Most Linux distros already have lesspipe enabled, but you can check for certain by running:

echo $LESSOPEN

If you don't see lesspipe or lessfile in the output, install lesspipe.

3. Configure Environment Variables

Add the following to ~/.bashrc

# sets LESSOPEN and LESSCLOSE variables
eval "$(SHELL=/bin/sh lesspipe)"

# interpret color characters
export LESS='-R'

# to list available styles: `pygmentize -L styles`
export PYGMENTIZE_STYLE='paraiso-dark'

# optional
alias ls='ls --color=always'
alias grep='grep --color=always'

If you don't have or want lesspipe, replace the above eval statement with:

export LESSOPEN='|~/.lessfilter %s'

4. Create ~/.lessfilter

Run main.py to generate the latest .lessfilter file and place it in your home directory. Or you can download a pre-generated .lessfilter which is currently at version 2.9.0. Check your program version by running pygmentize -V to ensure that it is this version or newer.

5. Make ~/.lessfilter executable

chmod +x ~/.lessfilter

All set! Test it out by running less ~/.lessfilter

Notes

The first time pygmentize is run in a shell session, you'll likely experience a cold-start delay. Subsequent invocations are much faster.

Description
A pygments-based syntax highlighter for less.
Readme 159 KiB
Languages
Python 76.9%
Shell 23.1%