speedwm-personal/modules/module_news
2022-10-27 17:51:19 +02:00

72 lines
1.4 KiB
Bash
Executable file

#!/bin/sh
# news module for status/stellar
# load config
. $HOME/.config/speedwm/statusrc
BINDIR="$(dirname $(command -v speedwm_status))/"
# argument 1
ARG1="$1"
# clicking
CLICK() {
# values
ICON="$ITEM10_ICON"
BUTTON="$(cat /tmp/speedwm-button)"
NEWS_COUNT="$(newsboat -x print-unread | awk '{ print $1 }')"
if [ "$NEWS_COUNT" = "Error:" ]; then
exit
fi
command -v newsboat > /dev/null || exit
case "$TERMINAL" in
"") TERMINAL=st
esac
case "$BUTTON" in
"3") $TERMINAL newsboat ; exit ;;
esac
# no spacing if there's no icon
if [ "$ICON" != "" ]; then
ICONSPACING=" " # one character spacing
fi
# send the notification
SEND_NOTIF() {
notify-send "${ICON}${ICONSPACING}$NEWS_COUNT $ITEM10_TEXT"
echo "Notification sent successfully!"
echo "INFO: ${ICON}${ICONSPACING}$NEWS_COUNT $ITEM10_TEXT"
exit 0
}
command -v notify-send > /dev/null && SEND_NOTIF
echo "FATAL: libnotify not installed, can't send notification."
exit 1
}
# information itself
PRINT() {
if [ "$ENABLE_ITEM10" = "true" ]; then
if [ -e "${BINDIR}newsboat" ]; then
newscount="$(newsboat -x print-unread | awk '{ print $1 }')"
if [ "$newscount" != "Error:" ]; then
echo "$SEPARATOR $ITEM10_ICON $newscount $ITEM10_TEXT"
fi
fi
fi
}
# argument 1
case "$ARG1" in
"") CLICK ;;
"--print") PRINT > /tmp/module_news ;;
"--click") CLICK ;;
esac