2016-07-20 11:47:18 +00:00
|
|
|
#!/bin/sh
|
2016-07-20 12:07:20 +00:00
|
|
|
# mless RANGES... - less(1)-wrapper around mshow
|
2016-07-20 11:47:18 +00:00
|
|
|
|
|
|
|
PATH="${0%/*}:$PATH"
|
|
|
|
|
|
|
|
if [ "$1" = --filter ]; then
|
2016-07-20 12:07:20 +00:00
|
|
|
mshow "$2" | awk '
|
2016-07-20 11:47:18 +00:00
|
|
|
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 }
|
2016-07-20 12:47:44 +00:00
|
|
|
/^--- .* ---/ { print fg(242, $0); next }
|
2016-07-20 11:47:18 +00:00
|
|
|
/^>/ { print fg(151, $0); next }
|
|
|
|
{ print }'
|
|
|
|
exit $?
|
|
|
|
fi
|
|
|
|
|
2016-07-20 12:48:02 +00:00
|
|
|
if [ "$#" -eq 0 ] && ! [ -t 0 ]; then
|
|
|
|
msetseq >/dev/null
|
|
|
|
set -- :
|
|
|
|
fi
|
|
|
|
|
2016-07-20 13:11:27 +00:00
|
|
|
if ! [ -t 1 ]; then
|
|
|
|
exec mseq "$@"
|
|
|
|
fi
|
|
|
|
|
2016-07-20 13:43:53 +00:00
|
|
|
case "$0" in
|
|
|
|
*next*) d=1;;
|
|
|
|
*prev*) d=-1;;
|
|
|
|
*) d=0;;
|
|
|
|
esac
|
2016-07-20 12:07:20 +00:00
|
|
|
curcmd=$(mseq -n "$@" |
|
2016-07-20 13:43:53 +00:00
|
|
|
awk -v cur=$(mseq -n .) -v d=$d '$1 == cur {print "+" FNR+d ":x"; quit}')
|
2016-07-20 11:47:18 +00:00
|
|
|
|
|
|
|
LESSOPEN="|$0 --filter %s" exec less -R $curcmd $(mseq -n "$@")
|