summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Pokorný <jpokorny@redhat.com>2013-04-23 19:09:56 +0200
committerJan Pokorný <jpokorny@redhat.com>2013-04-23 19:09:56 +0200
commit23d3a8d72461674f339b012292701b713b1c4b77 (patch)
tree38d6fec52b9689399ef196e1b70af62d4a6cfbc0
parent885b0d0a54efdcd2f47ced62af5d6d5ab6d8f815 (diff)
downloaddotfiles-23d3a8d72461674f339b012292701b713b1c4b77.tar.gz
dotfiles-23d3a8d72461674f339b012292701b713b1c4b77.tar.xz
dotfiles-23d3a8d72461674f339b012292701b713b1c4b77.zip
Make specified pager=less produce highlighted output if applicable
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
-rwxr-xr-x.local/bin/lesspipe-highlight.sh19
-rw-r--r--.profile1
2 files changed, 20 insertions, 0 deletions
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"
diff --git a/.profile b/.profile
index 65b844b..3bc5c99 100644
--- a/.profile
+++ b/.profile
@@ -2,3 +2,4 @@ export PATH="${PATH}:${HOME}/.local/bin:${HOME}/bin"
export KRB5_CONFIG="${HOME}/.krb5conf"
export EDITOR="vim"
export PAGER="less -FRXS"
+export LESSOPEN="||${HOME}/.local/bin/lesspipe-highlight.sh %s"