aboutsummaryrefslogtreecommitdiffstats
path: root/man/colourised-less-for-man
blob: e57fa184cb9a398527534557b3f4372299cc2017 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/bin/dash

colourise () {
	if test -n "$2"; then
		from="$(printf "$1"'\n' | sed 's/\[/\\[/g')"
		to="$(printf '%s\n' "$2" | sed 's/\[/\\[/g')"
		shift 2
		sed "s/$from/$to/g" | "$@"
	else
		shift 2
		"$@"
	fi
}

sed 's/\x1B\[\(.\)m\x1B\[2\(.\)m/\x1B\[2\2m\x1B\[\1m/g' | \
colourise "\033[4m" "${LESS_TERMCAP_us}" \
colourise "\033[24m" "${LESS_TERMCAP_ue}" \
colourise "\033[1m" "${LESS_TERMCAP_md}" \
colourise "\033[22m" "${LESS_TERMCAP_me}" \
colourise "\033[7m" "${LESS_TERMCAP_so}" \
colourise "\033[27m" "${LESS_TERMCAP_se}" \
less "$@"