summaryrefslogtreecommitdiffstats
path: root/.local/bin/lesspipe-highlight.sh
blob: 9f10416aa38c6d1a3c3eacf377e5ce9b652e5b0b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash
# TODO: cache source-highlight extensions?
# TODO: redo as ~/.lessfilter,
#       see https://bugzilla.redhat.com/show_bug.cgi?id=885122

# 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"