blob: 91267e053a560fa0aff2a83903dfd38df45139de (
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
37
|
#!/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 directly from newsboat's cache.db in
# read-only mode. We deliberately avoid `newsboat -x print-unread`: it needs
# the cache.db lock and prints NOTHING (exit 1, "an instance is already
# running") whenever another newsboat holds it — an open session or a slow
# `-x reload` — which blanked/flickered the block. A read-only+immutable query
# never locks, so it always returns the live count even mid-reload.
# NOTE: this counts every unread item in the DB, which matches print-unread
# only while the DB has no feeds outside ~/.config/newsboat/urls. If you remove
# a feed from urls, purge its leftover items so the count stays accurate:
# newsboat (open and quit once — cleanup-on-quit prunes orphaned feeds)
if [ -f /tmp/newsupdate ]; then
cat /tmp/newsupdate
else
db="${XDG_DATA_HOME:-${HOME}/.local/share}/newsboat/cache.db"
count=$(sqlite3 "file:${db}?mode=ro&immutable=1" \
"SELECT count(*) FROM rss_item WHERE unread=1 AND deleted=0;" 2>/dev/null)
[ "${count:-0}" -gt 0 ] 2>/dev/null && printf '📰%s' "$count"
cat "${XDG_CONFIG_HOME:-${HOME}/.config}"/newsboat/.update 2>/dev/null
echo
fi
|