2.0 KiB
Syntax highlighter for less
Uses Pygments to provide syntax highlighting
for supported file types. The .lessfilter is generated by parsing the Pygments documentation website.

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
2. Install lesspipe (recommended)
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.8.0.
Check your program version by running pygmentize -V to ensure it matches.
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.