speedwm-personal/modules/module_date

89 lines
2 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# date module for status/stellar
# load config
2022-10-27 17:51:19 +02:00
. $HOME/.config/speedwm/statusrc
2022-10-25 19:23:36 +02:00
BINDIR="$(dirname $(command -v speedwm_status))/"
ARG1="$1"
# click
CLICK() {
# values
DATE_DAY="$(date +%d)" # day number
DATE_DAY_OF_YEAR="$(date +%j)" # year day number
DATE_DAY_W_SHORT="$(date +%a)" # short day (ie. mon)
DATE_DAY_W_LONG="$(date +%A)" # long day (ie. monday)
DATE_MONTH="$(date +%m)" # month number
DATE_MONTH_W_SHORT="$(date +%b)" # short month (ie. oct)
DATE_MONTH_W_LONG="$(date +%B)" # long month (ie. october)
DATE_YEAR="$(date +%Y)" # year number
DATE_WEEK="$(date +%W)" # week number
DATE_WEEKDAY="$(date +%w)" # day of the week in number
ICON="$ITEM3_ICON" # icon is first argument
BUTTON="$(cat /tmp/speedwm-button)" # button
case "$TERMINAL" in
"") TERMINAL=st
esac
# no spacing if there's no icon
if [ "$ICON" != "" ]; then
ICONSPACING=" " # one character spacing
fi
2022-11-12 00:15:14 +01:00
case "$BUTTON" in
2022-11-12 00:49:10 +01:00
"3") RCAL ;;
2022-11-12 00:15:14 +01:00
esac
# send the notification
SEND_NOTIF() {
FULL_DATE="$(printf "${ICON}${ICONSPACING}$DATE_DAY_W_LONG, $DATE_MONTH_W_LONG, $DATE_DAY $DATE_YEAR\nWeek: $DATE_WEEK\nDay of the week: $DATE_WEEKDAY")"
notify-send "$FULL_DATE"
echo "Notification sent successfully!"
echo "INFO: $FULL_DATE"
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_ITEM3" = "true" ]; then
if [ -e "${DATEBINDIR}date" ]; then
DAY="$(date +%d)"
MONTH="$(date +%m)"
YEAR="$(date +%Y)"
echo "$SEPARATOR $ITEM3_ICON $ITEM3_FORMAT" | sed "s|@d|$DAY|; s|@m|$MONTH|; s|@y|$YEAR|"
fi
fi
}
2022-11-12 00:49:10 +01:00
# run calendar applet
RCAL() {
pgrep -x gsimplecal > /dev/null && isrunning=true
if [ "$isrunning" = "true" ]; then
pkill gsimplecal
exit
else
gsimplecal
isrunning=true
exit
fi
}
# argument 1
case "$ARG1" in
"") CLICK ;;
"--print") PRINT > /tmp/module_date ;;
"--click") CLICK ;;
esac