From 23d3a8d72461674f339b012292701b713b1c4b77 Mon Sep 17 00:00:00 2001 From: Jan Pokorný Date: Tue, 23 Apr 2013 19:09:56 +0200 Subject: Make specified pager=less produce highlighted output if applicable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jan Pokorný --- .local/bin/lesspipe-highlight.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100755 .local/bin/lesspipe-highlight.sh (limited to '.local/bin') diff --git a/.local/bin/lesspipe-highlight.sh b/.local/bin/lesspipe-highlight.sh new file mode 100755 index 0000000..b55e513 --- /dev/null +++ b/.local/bin/lesspipe-highlight.sh @@ -0,0 +1,19 @@ +#!/bin/bash +# TODO: cache source-highlight extensions? + +# XXX: enable overriding +LESSPIPE="$(which lesspipe.sh 2>/dev/null)" +SHLPIPE="$(which src-hilite-lesspipe.sh 2>/dev/null)" + +SHLEXTS= + +[ -x "${LESSPIPE}" ] || LESSPIPE=cat +[ -x "${SHLPIPE}" ] \ + && SHLEXTS=$(source-highlight --lang-list | cut -d = -f1 | sed 's/^/\*./' | paste -d'|' -s) \ + || SHLPIPE=cat + +eval "\ + case \"$1\" in + ${SHLEXTS%|}) ${SHLPIPE} "$1";; + *) ${LESSPIPE} "$1";; + esac" -- cgit