Blob


1 --- /usr/local/bin/mless Tue Oct 25 14:26:22 2022
2 +++ news Fri Nov 25 16:18:08 2022
3 @@ -1,23 +1,13 @@
4 #!/bin/sh
5 -# mless [MSG] - less(1)-wrapper around mshow
6 +# news - less(1) around mshow for my rss feeds
8 -colorscan() {
9 -awk '
10 -function co(n, c) { e = ENVIRON["MCOLOR_" n]; return e ? e : c }
11 -function fg(c, s) { return sprintf("\033[38;5;%03dm%s\033[0m", c, s) }
12 -function so(s) { return sprintf("\033[1m%s\033[0m", s) }
13 -/^>/ { print so(fg(co("CUR",119), $0)); next }
14 -/^ *\\_/ { print fg(co("MISS",242), $0); next }
15 -{ print }'
16 -}
17 +# use a custom mblaze env
18 +mkdir -p ~/.mblaze/news
19 +export MBLAZE=~/.mblaze/news
21 -if [ -n "${NO_COLOR+set}" ]; then
22 - colorscan() { cat -; }
23 -fi
24 -
25 if [ "$1" = --filter ]; then
26 if [ "$2" = //scan ]; then
27 - mscan : 2>/dev/null | colorscan
28 + mscan : 2>/dev/null
29 exit $?
30 fi
32 @@ -31,7 +21,7 @@
33 $((total - 1))) mscan .-4:.+1 ;;
34 $total) mscan .-5:.+0 ;;
35 *) mscan .-2:.+3 ;;
36 - esac 2>/dev/null | colorscan
37 + esac 2>/dev/null
38 echo
40 if ! [ -f "$(mseq -r "$2")" ]; then
41 @@ -85,6 +75,10 @@
42 elif [ -f "$HOME/.mless" ]; then
43 export LESSKEY="$HOME/.mless"
44 fi
45 +
46 +MAILFEEDS_DIR="${MAILFEEDS_DIR:-$HOME/Maildir/op/rss}"
47 +mlist -st "$MAILFEEDS_DIR" | mthread -r | mseq -S
48 +
49 while :; do
50 LESSOPEN="|$0 --filter %s" \
51 less -Ps"mless %f?m (message %i of %m).." -R \
52 @@ -96,6 +90,12 @@
53 ;;
54 78) # N go to next unseen message
55 nu=$(magrep -v -m1 :S .:) && mseq -C "$nu"
56 + ;;
57 + 79) # O open the news
58 + url="$(mhdr -h X-Rssgo-Email)"
59 + if [ $? -eq 0 -a -n "$url" ]; then
60 + xdg-open "$url"
61 + fi
62 ;;
63 107) # k next thread
64 mseq -C "$(mseq .+1: | sed -n '/^[^ <]/{p;q;}')"