Last active
May 1, 2023 01:01
-
-
Save textarcana/4611277 to your computer and use it in GitHub Desktop.
2020 update: just use bat(1) instead!!!! bat has git integration and also can show invisible characters! OLD STUFF: How to enable syntax-highlighting in less. Use `less -N` (or type -N while in less) to enable line numbers. Based on the procedure described in http://superuser.com/questions/71588
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Enable syntax-highlighting in less. | |
# Last tested on CentOS 6.3. | |
# | |
# First, add these two lines to ~/.bashrc | |
# export LESSOPEN="| /usr/bin/src-hilite-lesspipe.sh %s" | |
# export LESS=" -R " | |
sudo yum -y install boost boost-devel ctags | |
wget http://springdale.math.ias.edu/data/puias/unsupported/6/x86_64/source-highlight-3.1.6-3.puias6.x86_64.rpm | |
source-highlight-3.1.6-3.puias6.x86_64.rpm | |
sudo yum -y install source-highlight |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Enable syntax-highlighting in less. | |
# | |
# First, add these two lines to ~/.bashrc | |
# export LESSOPEN="| /opt/local/bin/src-hilite-lesspipe.sh %s" | |
# export LESS=" -R " | |
sudo port install source-highlight |
echo 'good luck with that' | less
On fish shell
what worked for me was:
$ brew install source-highlight
$ vim ~/.config/fish/functions/less.fish add the following content
function less
src-hilite-lesspipe.sh $argv | less -N
end
$ source ~/.config/fish/config.fish
$ less
For dark displays use the esc256 style in src-hilite-lesspipe.sh
:
#! /bin/bash
for source in "$@"; do
case $source in
*ChangeLog|*changelog)
source-highlight --failsafe -f esc256 --lang-def=changelog.lang --style-file=esc256.style -i "$source" ;;
*Makefile|*makefile)
source-highlight --failsafe -f esc256 --lang-def=makefile.lang --style-file=esc256.style -i "$source" ;;
*.tar|*.tgz|*.gz|*.bz2|*.xz)
lesspipe "$source" ;;
*) source-highlight --failsafe --infer-lang -f esc256 --style-file=esc256.style -i "$source" ;;
esac
done
( sed 's,esc,esc256,g'
will help ;)
2020 update I think that bat(1) replaces all of this and that one should use bat
going forward instead of the less / source-highlight combo. https://github.com/sharkdp/bat#syntax-highlighting
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem with
src-hilite-lesspipe
and friends is that if you use https://github.com/wofr06/lesspipe so that it opens binary files, using a such LESSOPEN breaks it.So I've defined something like in my
.bashrc
:It can indeed make it more complex, but it works for most of cases, so it will allow to use both default lesspipe (i.e. to open pdf or zip files) while it will colorize the text ones.