speedwm-personal/modules/module_news

56 lines
1.4 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# news module for status/stellar
# load config
module_config
[ -e "$HOME/.config/speedwm/statusrc" ] && . $HOME/.config/speedwm/statusrc
[ -e "/tmp/module_news_hidden" ] && exit
[ "$ENABLE_ITEM10" = "true" ] || exit
command -v newsboat > /dev/null || exit
NEWS_COUNT="$(newsboat -x print-unread | awk '{ print $1 }' || return)"
# clicking
CLICK() {
# values
ICON="$ITEM10_ICON"
[ "$NEWS_COUNT" = "Error:" ] && return
[ -e "/tmp/speedwm-button" ] && BUTTON="$(cat /tmp/speedwm-button)" || BUTTON="0"
[ -z "$TERMINAL" ] && TERMINAL=st
2022-12-16 17:35:03 +01:00
[ -n "$ICON" ] && ICONSPACING=" " # one character spacing
# check value of button
case "$BUTTON" in
"3") $TERMINAL newsboat ; return ;;
esac
# send the notification
SEND_NOTIF() {
notify-send "${ICON}${ICONSPACING}$NEWS_COUNT $ITEM10_TEXT"
# some information
echo "Notification sent successfully!"
echo "INFO: ${ICON}${ICONSPACING}$NEWS_COUNT $ITEM10_TEXT"
return
}
command -v notify-send > /dev/null && SEND_NOTIF || echo "FATAL: libnotify not installed, can't send notification."
return
}
# information itself
PRINT() {
[ "$NEWS_COUNT" = "Error:" ] && return || echo "$ITEM10_SEPARATOR $ITEM10_ICON $NEWS_COUNT $ITEM10_TEXT"
}
# argument 1
case "$1" in
"") CLICK ;;
"--print-file") PRINT > /tmp/module_news ;;
"--print") PRINT ;;
"--click") CLICK ;;
esac