blob: 8f4d7adb92b2d0a0b8c67a87ac45708a5569d5a6 (
plain)
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
|
#!/bin/sh
# Displays number of unread news items and an loading icon if updating.
# When clicked, brings up `newsboat`.
case $BLOCK_BUTTON in
1) setsid "$TERMINAL" -e newsboat ;;
2) setsid -f newsup >/dev/null && exit ;;
3) notify-send "📰 News module" "\- Shows unread news items
- Shows 📰🔃 if updating with \`newsup\`
- Left click opens newsboat
- Middle click syncs RSS feeds
<b>Note:</b> Only one instance of newsboat (including updates) may be running at a time" ;;
6) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;;
esac
# During a sync, `newsup` writes the spinner to /tmp/newsupdate; show that.
# Otherwise read the unread count. `newsboat -x print-unread` needs the cache.db
# lock and prints NOTHING (exit 1, "an instance is already running") whenever
# another newsboat holds it — e.g. a slow `-x reload`. Falling through to an
# empty block makes the icon vanish/flicker, so cache the last good count and
# reuse it when the read fails.
if [ -f /tmp/newsupdate ]; then
cat /tmp/newsupdate
else
cache="${XDG_CACHE_HOME:-${HOME}/.cache}/newsunread"
count=$(newsboat -x print-unread 2>/dev/null | awk '{print $1}')
if [ -n "$count" ]; then
printf '%s' "$count" >"$cache"
else
count=$(cat "$cache" 2>/dev/null) # DB locked → reuse last known value
fi
[ "${count:-0}" -gt 0 ] 2>/dev/null && printf '📰%s' "$count"
cat "${XDG_CONFIG_HOME:-${HOME}/.config}"/newsboat/.update 2>/dev/null
echo
fi
|