dwm-speedie/modules/module_news
2023-09-13 15:24:02 +02:00

56 lines
1.3 KiB
Bash
Executable file

#!/bin/sh
# news module for status/stellar
# load config
module_config
[ -e "$HOME/.config/dwm/statusrc" ] && . $HOME/.config/dwm/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/dwm-button" ] && BUTTON="$(cat /tmp/dwm-button)" || BUTTON="0"
[ -z "$TERMINAL" ] && TERMINAL=st
[ -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