dotfiles/.local/bin/newsboatnotifs

33 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
#gets called by newsboat if it finds a new article.
CACHE="${XDG_DATA_HOME:-$HOME/.local/share}/newsboat/cache.db"
CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}/newsboat/urls"
ALREADY_NOTIFIED="${XDG_DATA_HOME:-$HOME/.local/share}/newsboat/notified"
[ -f "$ALREADY_NOTIFIED" ] || touch "$ALREADY_NOTIFIED"
unread="$(sqlite3 "$CACHE" "SELECT unread,pubDate,title,feedurl FROM rss_item;" |
grep -vE '^0' | sort -t'|' -k2 -gr |
grep -vf "$ALREADY_NOTIFIED")"
[ -z "$unread" ] && exit
echo "$unread" >> "$ALREADY_NOTIFIED"
[ "$( echo "$unread" | wc -l)" -gt 1 ] && plural=s
articles="$(echo "$unread" | cut -d'|' -f3,4)"
echo "$articles" | while read -r article; do
#remove '?' queries from URL
title="$(echo "$article" | cut -d'|' -f1)"
feed="$(echo "$article" | cut -d'|' -f2 | sed 's/?.*//')"
#Find custom name given via name tag in CONFIG
name="$(grep "$feed" "$CONFIG" | grep '~' |
perl -pe "s/[^~\"]*\"~([^\"]*).*/\1/")"
#If no custom name present, use name from CACHE
echo "$feed"
if [ -z "$name" ]; then
name="$(sqlite3 "$CACHE" "SELECT rssurl,title FROM rss_feed;" |
grep -F "$feed" | cut -d'|' -f2)"
fi
notify-send "${name}:" "$title"
done
#update statusbar to account for new articles
pkill -RTMIN+13 dwmblocks