2016-07-20 11:47:18 +00:00
|
|
|
#!/bin/sh
|
2016-07-28 21:10:45 +00:00
|
|
|
# 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
|
|
|
|
|
2016-07-28 21:10:45 +00:00
|
|
|
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
|
|
|
|
|
2016-07-20 12:48:02 +00:00
|
|
|
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 -- :
|
2016-07-20 12:48:02 +00:00
|
|
|
fi
|
|
|
|
|
2016-07-20 13:11:27 +00:00
|
|
|
if ! [ -t 1 ]; then
|
2016-07-28 21:10:45 +00:00
|
|
|
exec mseq :
|
2016-07-20 13:11:27 +00:00
|
|
|
fi
|
|
|
|
|
2016-07-20 13:43:53 +00:00
|
|
|
case "$0" in
|
2016-07-28 21:10:45 +00:00
|
|
|
*mnext) set -- +;;
|
|
|
|
*mprev) set -- -;;
|
2016-08-02 20:50:45 +00:00
|
|
|
*) [ "$#" -eq 1 ] && set -- ${1:-.};;
|
2016-07-20 13:43:53 +00:00
|
|
|
esac
|
2016-07-20 11:47:18 +00:00
|
|
|
|
2016-08-02 20:50:45 +00:00
|
|
|
if [ "$#" -ge 1 ]; then
|
2016-07-28 21:10:45 +00:00
|
|
|
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
|
2016-07-28 21:46:02 +00:00
|
|
|
while :; do
|
2016-09-01 23:50:20 +00:00
|
|
|
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
|
2016-07-28 21:46:02 +00:00
|
|
|
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 :)
|
2016-07-28 21:46:02 +00:00
|
|
|
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"
|
|
|
|
;;
|
2016-07-28 21:46:02 +00:00
|
|
|
107) # k next thread
|
2016-08-02 15:17:17 +00:00
|
|
|
mseq -C "$(mseq .+1: | grep -m1 '^[^ <]')"
|
|
|
|
;;
|
2016-07-28 21:46:02 +00:00
|
|
|
100) # d mark read
|
|
|
|
mflag -S .
|
2016-07-28 21:51:22 +00:00
|
|
|
mseq -f : | mseq -S
|
2016-07-28 21:46:02 +00:00
|
|
|
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
|
|
|
|
;;
|
2016-07-28 21:46:02 +00:00
|
|
|
esac
|
|
|
|
done
|