-
Notifications
You must be signed in to change notification settings - Fork 0
/
hl
28 lines (28 loc) · 910 Bytes
/
hl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# hl - highlight
# Takes a maximum of 28 "egrep" regex-es as parameters, and highlights them in the text coming from stdin, using various colors.
# Patterns to the right are "stronger", but keep in mind that the input might already contain ANSI control characters.
function hl ()
{
local cmd
local i
local color
i=1
cmd="cat"
while [[ $# -gt 0 ]]; do
if [[ "${1}" != "." ]]; then # Use "." to skip a color you don't like
if [[ $i -lt 8 ]]; then
color="7\;$(( 30 + ${i} ))" # background
elif [[ $i -lt 14 ]]; then
color="$(( 30 - 7 + ${i} ))" # foreground color
elif [[ $i -lt 21 ]]; then
color="7\;2\;$(( 30 - 13 + ${i} ))" # background, faint
elif [[ $i -lt 28 ]]; then
color="4\;$(( 30 - 20 + ${i} ))" # underlined, foreground
fi
cmd="$cmd | GREP_COLOR="${color}" egrep --color=always --line-buffered '${1}|$'"
fi
shift
i=$(( $i+1 ))
done
$SHELL -c "$cmd"
}