From 0471af2f72a5c30c5f0fc1d3c54dfb660f63b76c Mon Sep 17 00:00:00 2001 From: doryan Date: Thu, 3 Oct 2024 00:45:19 +0400 Subject: [PATCH] feat(script): add calendar script --- polybar/calendar | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 polybar/calendar diff --git a/polybar/calendar b/polybar/calendar new file mode 100755 index 0000000..19c2f86 --- /dev/null +++ b/polybar/calendar @@ -0,0 +1,32 @@ +#!/bin/bash + +send_notification() { + TODAY=$(date '+%-d') + HEAD=$(cal "$1" | head -n1) + BODY=$(cal "$1" | tail -n7 | sed -z "s|$TODAY|$TODAY|1") + FOOT="\n ~ calendar 󰸗 " + 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