about summary refs log tree commit diff
path: root/mless
diff options
context:
space:
mode:
authorChristian Neukirchen <chneukirchen@gmail.com>2016-07-20 13:47:18 +0200
committerChristian Neukirchen <chneukirchen@gmail.com>2016-07-20 13:47:47 +0200
commit94f7343793b04409b57f5657a70b6c6cf024e3cd (patch)
treee86ac6a07a48ec0872ba7594e1b04c727108e3eb /mless
parent30b94679d6f453dc98b3ce2d618b1252bf6b8584 (diff)
downloadmblaze-94f7343793b04409b57f5657a70b6c6cf024e3cd.tar.gz
mblaze-94f7343793b04409b57f5657a70b6c6cf024e3cd.tar.xz
mblaze-94f7343793b04409b57f5657a70b6c6cf024e3cd.zip
add mless
Diffstat (limited to 'mless')
-rwxr-xr-xmless23
1 files changed, 23 insertions, 0 deletions
diff --git a/mless b/mless
new file mode 100755
index 0000000..4e22f69
--- /dev/null
+++ b/mless
@@ -0,0 +1,23 @@
+#!/bin/sh
+# mless RANGES... - less(1)-wrapper around show
+
+PATH="${0%/*}:$PATH"
+
+if [ "$1" = --filter ]; then
+	show "$2" | 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 }
+/^$/ { hdr = 0 }
+hdr && /^From:/ { print so(fg(119, $0)); next }
+hdr { print fg(120, $0); next }
+/^---.*---/ { print fg(242, $0); next }
+/^>/ { print fg(151, $0); next }
+{ print }'
+	exit $?
+fi
+
+cur=$(mseq -n .)
+curcmd=$(mseq -n "$@" | awk -v cur=$cur '$1 == cur {print "+" FNR ":x"; quit}')
+
+LESSOPEN="|$0 --filter %s" exec less -R $curcmd $(mseq -n "$@")