Skip to content
Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
..
Failed to load latest commit information.
README.md

README.md

SOURCE CODE SYNTAX HIGHLIGHTING IN "LESS"

Introduction.

If you are a linux specialist, you surelly know the pager program "less". One of the things you can do with less on most modern linux distros, is configure "syntax highlighting" on it. This short recipe will show you how to modify your linux environment in order to add syntax highlighting to the "less" pager.

YUM Distros (CENTOS/FEDORA):

In Centos/Fedora, first install the source-highligh package:

yum install source-highlight

NOTE: In Centos/RHEL distros, you NEED the "EPEL" repository installed.

Fedora 2X:

In your Fedora machine (20-23 and later), run the following commands:

export LESSOPEN="| /bin/src-hilite-lesspipe.sh %s"
export LESS=' -R '

echo "export LESSOPEN=\"| /bin/src-hilite-lesspipe.sh %s\"" > /etc/profile.d/less-hl.sh
echo "export LESS=' -R '" >> /etc/profile.d/less-hl.sh

RHEL/CENTOS (Series 6):

In your RHEL/Centos 6.x, run the following commands:

export LESSOPEN="| /usr/bin/src-hilite-lesspipe.sh %s"
export LESS=' -R '

echo "export LESSOPEN=\"| /usr/bin/src-hilite-lesspipe.sh %s\"" > /etc/profile.d/less-hl.sh
echo "export LESS=' -R '" >> /etc/profile.d/less-hl.sh

RHEL/CENTOS (Series 7):

In your RHEL/Centos 7.x, run the following commands:

export LESSOPEN="| /usr/bin/src-hilite-lesspipe.sh %s"
export LESS=' -R '

echo "export LESSOPEN=\"| /usr/bin/src-hilite-lesspipe.sh %s\"" > /etc/profile.d/less-hl.sh
echo "export LESS=' -R '" >> /etc/profile.d/less-hl.sh

APT DISTROS (DEBIAN/UBUNTU)

Debian 7 and 8:

Install the package:

apt-get install source-highlight

Run the following commands:

export LESSOPEN="| /usr/share/source-highlight/src-hilite-lesspipe.sh %s"
export LESS=' -R '

echo "export LESSOPEN=\"| /usr/share/source-highlight/src-hilite-lesspipe.sh %s\"" > /etc/profile.d/less-hl.sh
echo "export LESS=' -R '" >> /etc/profile.d/less-hl.sh

Ubuntu 14.04lts and 16.04lts:

Install the package:

apt-get install source-highlight

Run the following commands:

export LESS=' -R '

echo "export LESS=' -R '" >> /etc/profile.d/less-hl.sh

Create the following file:

vi /root/.lessfilter

Containing:

#!/bin/sh
file -b -L "$1" | grep -q text && \
/usr/share/source-highlight/src-hilite-lesspipe.sh "$1"

Change the file permissions, and copy it to skel directory:

chmod 755 /root/.lessfilter

cp /root/.lessfilter /etc/skel/

chmod 755 /etc/skel/.lessfilter

If you already have users created in your system, copy the .lessfilter to their home dirs and adjust the permissions in order to let them have syntax highlighting with less. Any new user will be provided with the filters as it comes directly from the skel.

END.-

You can’t perform that action at this time.