You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mblaze/mless

69 lines
1.4 KiB
Plaintext

8 years ago
#!/bin/sh
8 years ago
# mless RANGES... - less(1)-wrapper around mshow
8 years ago
PATH="${0%/*}:$PATH"
colormsg() {
awk '
8 years ago
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 }
8 years ago
/^>/ { 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 }'
}
mnums() {
mscan "$@" 2>/dev/null | awk '$2 ~ /^[0-9]*$/ { print $2 }'
}
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
8 years ago
exit $?
fi
if [ "$#" -eq 0 ] && ! [ -t 0 ]; then
msetseq >/dev/null
set -- //scan :
fi
if ! [ -t 1 ]; then
exec mseq "$@"
fi
case "$0" in
*next*) d=1;;
*prev*) d=-1;;
*) d=0;;
esac
curcmd=$(mnums "$@" |
awk -v cur=$(mseq -n .) -v d=$d '$1 == cur {print "+" FNR+d ":x"; quit}')
8 years ago
LESSOPEN="|$0 --filter %s" exec less -Ps"mless %f?m (message %i of %m).." -R $curcmd $(mnums "$@")