about summary refs log tree commit diff
path: root/mless
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-07-24 23:38:00 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2016-07-24 23:38:00 +0200
commit05174158cdfab5dcae92244518ac972b141df4a5 (patch)
treedfe569152b89ae48a0de22f61bbb7377dd4618b0 /mless
parentb644998fe617da46f2d57318bfa8a45832beb25e (diff)
downloadmblaze-05174158cdfab5dcae92244518ac972b141df4a5.tar.gz
mblaze-05174158cdfab5dcae92244518ac972b141df4a5.tar.xz
mblaze-05174158cdfab5dcae92244518ac972b141df4a5.zip
mless: show context before each mail
Diffstat (limited to 'mless')
-rwxr-xr-xmless38
1 files changed, 29 insertions, 9 deletions
diff --git a/mless b/mless
index 6e4ebc1..9d3be24 100755
--- a/mless
+++ b/mless
@@ -3,15 +3,8 @@
 
 PATH="${0%/*}:$PATH"
 
-if [ "$1" = --filter ]; then
-	[ "$2" = //scan ] && exec mscan :
-
-	if ! [ -f $(mseq "$2") ]; then
-		mseq "$2"
-		exit
-	fi
-
-	mshow "$2" | awk '
+colormsg() {
+awk '
 function fg(c, s) { return sprintf("\033[38;5;%03dm%s\033[0m", c, s) }
 function so(s) { return sprintf("\033[1m%s\033[0m", s) }
 BEGIN { hdr = 1 }
@@ -21,6 +14,33 @@ hdr { print fg(120, $0); next }
 /^--- .* ---/ { print fg(242, $0); next }
 /^>/ { print fg(151, $0); next }
 { print }'
+}
+
+colorscan() {
+awk '
+function fg(c, s) { return sprintf("\033[38;5;%03dm%s\033[0m", c, s) }
+function so(s) { return sprintf("\033[1m%s\033[0m", s) }
+/^>/ { print so(fg(119, $0)); next }
+/^ *\\_/ { print fg(242, $0); next }
+{ print }'
+}
+
+if [ "$1" = --filter ]; then
+	if [ "$2" = //scan ]; then
+		mscan : 2>/dev/null | colorscan
+		exit $?
+	fi
+
+	mshow -q "$2" > /dev/null
+	mscan .-2:.+3 2>/dev/null | colorscan
+	echo
+
+	if ! [ -f $(mseq "$2") ]; then
+		mseq "$2"
+		exit
+	fi
+
+	mshow "$2" | colormsg
 	exit $?
 fi