mirror of https://github.com/leahneukirchen/mblaze
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.
76 lines
1.5 KiB
Bash
76 lines
1.5 KiB
Bash
#!/bin/sh
|
|
# mless [MSG] - less(1)-wrapper around mshow
|
|
|
|
PATH="${0%/*}:$PATH"
|
|
|
|
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 }
|
|
/^$/ { hdr = 0 }
|
|
/^-- $/ { ftr = 1 }
|
|
/^--- .* ---/ { print fg(242, $0); ftr = 0; sig = 0; next }
|
|
/^-----BEGIN .* SIGNATURE-----/ { sig = 1 }
|
|
hdr && /^From:/ { print so(fg(119, $0)); next }
|
|
hdr { print fg(120, $0); next }
|
|
ftr { print fg(244, $0); next }
|
|
/^-----BEGIN .* MESSAGE-----/ ||
|
|
/^-----END .* SIGNATURE-----/ { print fg(244, $0); sig = 0; next }
|
|
sig { print fg(244, $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
|
|
|
|
mseq -C "$2"
|
|
mscan .-2:.+3 2>/dev/null | colorscan
|
|
echo
|
|
|
|
if ! [ -f "$(mseq -r "$2")" ]; then
|
|
mseq "$2"
|
|
exit
|
|
fi
|
|
|
|
mshow "$2" | colormsg
|
|
exit $?
|
|
fi
|
|
|
|
if [ "$#" -eq 0 ] && ! [ -t 0 ]; then
|
|
mseq -S >/dev/null
|
|
set -- :
|
|
fi
|
|
|
|
if ! [ -t 1 ]; then
|
|
exec mseq :
|
|
fi
|
|
|
|
case "$0" in
|
|
*mnext) set -- +;;
|
|
*mprev) set -- -;;
|
|
*) set -- ${1:-.};;
|
|
esac
|
|
|
|
if [ "$#" -eq 1 ]; then
|
|
mseq -C "$1"
|
|
fi
|
|
|
|
nl="
|
|
"
|
|
LESSOPEN="|$0 --filter %s" exec less -Ps"mless %f?m (message %i of %m).." -R \
|
|
"+:e $(mseq -n .)$nl" //scan $(mseq -n :)
|