mblaze/mless

102 lines
1.8 KiB
Plaintext
Raw Normal View History

2016-07-20 11:47:18 +00:00
#!/bin/sh
# mless [MSG] - less(1)-wrapper around mshow
2016-07-20 11:47:18 +00:00
PATH="${0%/*}:$PATH"
2016-07-24 21:38:00 +00:00
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
2016-07-26 15:21:39 +00:00
mseq -C "$2"
2016-07-24 21:38:00 +00:00
mscan .-2:.+3 2>/dev/null | colorscan
echo
if ! [ -f "$(mseq -r "$2")" ]; then
2016-07-24 21:38:00 +00:00
mseq "$2"
exit
fi
2016-07-29 10:07:33 +00:00
if [ $MLESS_RAW -eq 0 ]; then
2016-07-29 15:12:37 +00:00
if [ $MLESS_HTML -eq 1 ]; then
mshow -A text/html "$2"
else
mshow "$2"
2016-08-02 20:50:45 +00:00
fi | mcolor
2016-07-29 10:07:33 +00:00
else
mseq -r $2
echo
cat "$(mseq -r $2)"
fi
2016-07-20 11:47:18 +00:00
exit $?
fi
if [ "$#" -eq 0 ] && ! [ -t 0 ]; then
2016-07-26 14:39:10 +00:00
mseq -S >/dev/null
2016-07-26 11:44:07 +00:00
set -- :
fi
if ! [ -t 1 ]; then
exec mseq :
fi
case "$0" in
*mnext) set -- +;;
*mprev) set -- -;;
2016-08-02 20:50:45 +00:00
*) [ "$#" -eq 1 ] && set -- ${1:-.};;
esac
2016-07-20 11:47:18 +00:00
2016-08-02 20:50:45 +00:00
if [ "$#" -ge 1 ]; then
mseq -C "$1"
fi
nl="
"
2016-07-29 10:07:33 +00:00
export MLESS_RAW=0
2016-07-29 15:12:37 +00:00
export MLESS_HTML=0
while :; do
if [ -f $MBLAZE/mless ]; then
export LESSKEY=$MBLAZE/mless
elif [ -f $HOME/.mblaze/mless ]; then
export LESSKEY=$HOME/.mblaze/mless
elif [ -f $HOME/.mless ]; then
export LESSKEY=$HOME/.mless
fi
LESSOPEN="|$0 --filter %s" \
less -Ps"mless %f?m (message %i of %m).." -R \
2016-07-31 17:46:43 +00:00
"+:e $(mscan -n .)$nl" //scan $(mscan -n :)
case "$?" in
0|1) exit $?;;
2016-07-28 21:48:08 +00:00
78) # N go to next unseen message
2016-08-02 15:17:17 +00:00
nu=$(magrep -v -m1 :S .:) && mseq -C "$nu"
;;
107) # k next thread
2016-08-02 15:17:17 +00:00
mseq -C "$(mseq .+1: | grep -m1 '^[^ <]')"
;;
100) # d mark read
mflag -S .
2016-07-28 21:51:22 +00:00
mseq -f : | mseq -S
mseq -C +
2016-07-29 10:07:33 +00:00
;;
82) # R toggle raw mode
MLESS_RAW=$((1-$MLESS_RAW))
2016-07-29 15:12:37 +00:00
;;
72) # H toggle HTML mode
MLESS_HTML=$((1-$MLESS_HTML))
;;
2016-08-08 15:39:25 +00:00
94) # ^ goto parent
mseq -C '.^' 2>/dev/null
;;
esac
done