#! /bin/bash
send_notification() {
TODAY=$(date '+%-d')
HEAD=$(cal "$1" | head -n1)
BODY=$(cal "$1" | tail -n7 | sed -z "s|$TODAY|<u><b>$TODAY</b></u>|1")
FOOT="\n<i> ~ calendar</i> B. Raucci"
dunstify -h string:x-canonical-private-synchronous:calendar \
"$HEAD" "$BODY$FOOT" -u NORMAL
}
handle_action() {
echo "$DIFF" > "$TMP"
if [ "$DIFF" -ge 0 ]; then
send_notification "+$DIFF months"
else
send_notification "$((-DIFF)) months ago"
fi
}
TMP=${XDG_RUNTIME_DIR:-/tmp}/"$UID"_calendar_notification_month
touch "$TMP"
DIFF=$(<"$TMP")
case $1 in
"curr") DIFF=0;;
"next") DIFF=$((DIFF+1));;
"prev") DIFF=$((DIFF-1));;
esac
handle_action
The calendar
script is responsible for handling mouse events triggered by your bar, following are valid arguments:
./calendar curr # current month
./calendar next # increment month
./calendar prev # decrement month
Copy calendar
to your polybar config directory. Then, in your polybar config, you can use click-left
, scroll-up
and scroll-down
actions to invoke the script. For example:
[module/calendar]
type = custom/script
label = " "
exec = echo Calendar
click-left = ~/.config/polybar/calendar curr
scroll-up = ~/.config/polybar/calendar next
scroll-down = ~/.config/polybar/calendar prev