speedwm-personal/modules/module_email

52 lines
1.4 KiB
Plaintext
Raw Normal View History

2022-12-16 18:12:06 +01:00
#!/bin/sh
# email module for status/stellar
# load config
module_config
[ -z "$ITEM12_EMAIL_DIR" ] && ITEM12_EMAIL_DIR="$HOME/.local/share/mail"
[ -e "$HOME/.config/speedwm/statusrc" ] && . $HOME/.config/speedwm/statusrc
[ -z "$ICON" ] && ICON="$ITEM12_ICON"
[ -z "$EMAIL_UNREADS" ] && EMAIL_UNREADS="$(find $ITEM12_EMAIL_DIR/*/[Ii][Nn][Bb][Oo][Xx]/new/* -type f >/tmp/module_email_data 2>/dev/null && wc -l </tmp/module_email_data || echo 0)"
[ -d "$ITEM12_EMAIL_DIR" ] || exit
[ -e "/tmp/module_email_hidden" ] && exit
2022-12-16 18:12:06 +01:00
# clicking
CLICK() {
[ -e "/tmp/speedwm-button" ] && BUTTON="$(cat /tmp/speedwm-button)" || BUTTON="0"
# default terminal
[ -z "$TERMINAL" ] && TERMINAL=st
# enable icon spacing
[ -n "$ICON" ] && ICONSPACING=" " # one character spacing
2022-12-16 18:12:06 +01:00
# send the notification
SEND_NOTIF() {
FULL_EMAIL="${ICON}${ICONSPACING}$EMAIL_UNREADS"
2022-12-16 18:16:00 +01:00
notify-send "$FULL_EMAIL $ITEM12_UNREAD_TEXT"
2022-12-16 18:12:06 +01:00
echo "Notification sent successfully!"
2022-12-16 18:16:00 +01:00
echo "INFO: $FULL_EMAIL $ITEM12_UNREAD_TEXT"
2022-12-16 18:12:06 +01:00
exit 0
}
2022-12-16 18:12:06 +01:00
command -v notify-send > /dev/null && SEND_NOTIF || echo "FATAL: libnotify not installed, can't send notification."
exit 1
}
# information itself
PRINT() {
[ "$ENABLE_ITEM12" != "true" ] && return
2022-12-16 18:16:00 +01:00
echo "$ITEM12_SEPARATOR $ICON $EMAIL_UNREADS $ITEM12_UNREAD_TEXT"
2022-12-16 18:12:06 +01:00
}
# argument 1
case "$1" in
"") CLICK ;;
2022-12-16 20:01:45 +01:00
"--print-file") PRINT > /tmp/module_email ;;
2022-12-16 18:12:06 +01:00
"--print") PRINT ;;
"--click") CLICK ;;
esac