# 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 |
# 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 |
This comment has been minimized.
This comment has been minimized.
Awesome! |
This comment has been minimized.
This comment has been minimized.
This is great! Note that, for homebrew, the script is located at: |
This comment has been minimized.
This comment has been minimized.
Neat. on mac os x I have added the following to my less setup in .bashrc
Thanks for the pointer to this. very helpful |
This comment has been minimized.
This comment has been minimized.
Thanks @textarcana & @rubytester! |
This comment has been minimized.
This comment has been minimized.
A little different in on my arch ~/.zshrc
|
This comment has been minimized.
This comment has been minimized.
That's awesome. I've set mine up with ### Terminal Syntax Highlighting
# Setup: "brew install highlight"
# Pipe Highlight to less
export LESSOPEN="| $(which highlight) %s --out-format xterm256 --line-numbers --quiet --force --style solarized-light"
export LESS=" -R"
alias less='less -m -N -g -i -J --line-numbers --underline-special'
alias more='less'
# Use "highlight" in place of "cat"
alias cat="highlight $1 --out-format xterm256 --line-numbers --quiet --force --style solarized-light"
# Setup JSON Syntax Highlighting
# Copy js.lang to json.lang with the following command
# cp "$(dirname $(brew list highlight | head -n 1))/share/highlight/langDefs/js.lang" "$(dirname $(brew list highlight | head -n 1))/share/highlight/langDefs/json.lang" I found |
This comment has been minimized.
This comment has been minimized.
Thanks for sharing your config @F1LT3R! |
This comment has been minimized.
This comment has been minimized.
@F1LT3R Thanks! The Solarized color scheme of |
This comment has been minimized.
This comment has been minimized.
for aquatic shell jockeys # ~/.config/fish/config.fish
set hilite (which highlight)
set -x LESSOPEN "| $hilite %s --out-format xterm256 --quiet --force "
set -x LESS " -R" # ~/.config/fish/functions/less.fish
function less
command less -m -N -g -i -J --underline-special --SILENT $argv
end |
This comment has been minimized.
This comment has been minimized.
@F1LT3R Any ideas how to tell |
This comment has been minimized.
This comment has been minimized.
Actual way to make less work on fish shell since @bennypowers solution didn't work for me: # ~/.config/fish/config.fish
# or
# ~/.config/omf/init.fish
# If you're using oh-my-fish
set hilite (which src-hilite-lesspipe.sh)
set -x LESSOPEN "| $hilite %s"
set -x LESS " -R -X -F " |
This comment has been minimized.
This comment has been minimized.
First install on Linux Mint or Ubuntu
add at end of on my arch ~/.zshrc also works on ~/.bashrc # Enable syntax-highlighting in less.
# apt-get install source-highlight
export LESSOPEN="| /usr/share/source-highlight/src-hilite-lesspipe.sh %s"
export LESS=" -R "
alias less='less -m -N -g -i -J --underline-special --SILENT'
alias more='less'
|
This comment has been minimized.
This comment has been minimized.
At last I cannot put this in |
This comment has been minimized.
This comment has been minimized.
So how do I avoid only being able to see the top of the file because of:
printed to stderr? Can there be some sort of "if highlighting fails, just do a normal less"? |
This comment has been minimized.
This comment has been minimized.
Use Vim as PAGER https://github.com/rkitover/vimpager |
This comment has been minimized.
This comment has been minimized.
The problem with So I've defined something like in my lesscolors()
{
env LESSOPEN='| /usr/share/source-highlight/src-hilite-lesspipe.sh %s' \
LESS=' --RAW-CONTROL-CHARS ' \
$(which less) $@
}
less()
{
less=$(which less)
has_file=false
all_text=true
for arg in $@; do
if [[ "$arg" != -* ]] && [ -e "$arg" ]; then
has_file=true
enc=$(file -b --mime-encoding "$(realpath $arg)")
if [[ "$enc" != *"-ascii" ]] && [ "$enc" != "utf-8" ]; then
all_text=false
break
fi
fi
done
if [ $has_file == true ] && [ "$all_text" == true ]; then
less=lesscolors
fi
$less $@
} 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. |
This comment has been minimized.
This comment has been minimized.
echo 'good luck with that' | less |
This comment has been minimized.
This comment has been minimized.
On $ brew install source-highlight
$ source ~/.config/fish/config.fish |
This comment has been minimized.
This comment has been minimized.
For dark displays use the esc256 style in
( |
This comment has been minimized.
This comment has been minimized.
2020 update I think that bat(1) replaces all of this and that one should use |
This comment has been minimized.
And here's how to install source-highlight with HomeBrew (thx Kastner):
brew install source-highlight