This repository has been archived by the owner on Apr 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmuchless
executable file
·133 lines (123 loc) · 2.77 KB
/
muchless
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/sh
# muchless [MSG] - less(1)-wrapper around mshow, with notmuch additions
. $(dirname "$(readlink -f "$0")")/mblaze_much.sh
colorscan() {
awk '
function co(n, c) { e = ENVIRON["MCOLOR_" n]; return e ? e : c }
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(co("CUR",119), $0)); next }
/^ *\\_/ { print fg(co("MISS",242), $0); next }
{ print }'
}
if [ -n "${NO_COLOR+set}" ]; then
colorscan() { cat -; }
fi
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
if [ $MLESS_RAW -eq 0 ]; then
if [ $MLESS_HTML -eq 1 ]; then
echo "X-Tags: $(mtags "$2")"
mshow -A text/html "$2"
else
echo "X-Tags: $(mtags "$2")"
mshow "$2"
fi | mcolor
else
mseq -r $2
echo
cat "$(mseq -r $2)"
fi
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 -- -;;
*) [ "$#" -eq 1 ] && set -- ${1:-.};;
esac
if [ "$#" -ge 1 ]; then
mseq -C "$1"
fi
nl="
"
export MLESS_RAW=0
export MLESS_HTML=0
while :; do
if [ -f $MBLAZE/muchless ]; then
export LESSKEY=$MBLAZE/muchless
elif [ -f $HOME/.mblaze/muchless ]; then
export LESSKEY=$HOME/.mblaze/muchless
elif [ -f $HOME/.muchless ]; then
export LESSKEY=$HOME/.muchless
fi
LESSOPEN="|$0 --filter %s" \
less -Ps"mless %f?m (message %i of %m).." -R \
"+:e $(mscan -n .)$nl" //scan $(mscan -n :)
case "$?" in
0|1) exit $?;;
36) # $ goto end
mseq -C '$' 2>/dev/null
;;
78) # N go to next unseen message
nu=$(magrep -v -m1 :S .:) && mseq -C "$nu"
;;
107) # k next thread
mseq -C "$(mseq .+1: | sed -n '/^[^ <]/{p;q;}')"
;;
100) # d mark read
mflag -S .
mseq -f : | mseq -S
mseq -C +
;;
82) # R toggle raw mode
MLESS_RAW=$((1-$MLESS_RAW))
;;
72) # H toggle HTML mode
MLESS_HTML=$((1-$MLESS_HTML))
;;
94) # ^ goto parent
mseq -C '.^' 2>/dev/null
;;
97) # a archive single mail
march .
;;
88) # X extract file
(cd ~/tmp; mshow -x .)
;;
114) # r reply
mrep .
;;
102) # f forward
mfwd .
;;
115) # s mark as spam single mail
mspam .
;;
118) # v open HTML in mutt
WORKDIR=$(mktemp -d --tmpdir muchlessXXXXXX)
if [ "$WORKDIR" = "" -o ! -d "$WORKDIR" ]; then
echo "Could not create temp dir"
exit 1
fi
(cd $WORKDIR && xdg-open $(mshow -x . $(mshow -t . | grep "text/html" | sed 's/:.*$//g' )) )
(sleep 5 && rm $WORKDIR/* && rmdir $WORKDIR) &
;;
esac
done