aboutsummaryrefslogtreecommitdiff
path: root/scripts/util/bday.sh
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/util/bday.sh')
-rwxr-xr-xscripts/util/bday.sh47
1 files changed, 47 insertions, 0 deletions
diff --git a/scripts/util/bday.sh b/scripts/util/bday.sh
new file mode 100755
index 0000000..72ac556
--- /dev/null
+++ b/scripts/util/bday.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+
+# I'm forgetful of these things
+
+today=$(date '+%m/%d')
+run_date=$(date '+%Y-%m-%d')
+#F_BDAY_RECORDS="bdays.txt"
+F_BDAY_RECORDS=~/.local/share/bdays.txt
+BDAY_IMG=~/Digital/Pictures/Backgrounds/birthday.png
+
+last_run=$(
+ grep '^# last run:' "$F_BDAY_RECORDS" 2>/dev/null \
+ | tail -n1 \
+ | awk '{ print $4 }'
+)
+[ "$last_run" = "$run_date" ] && exit 0
+
+
+BDAY_LIST=$(awk -v td="$today" '
+ $0 ~ /^[[:space:]]*#/ { next } # skip comments
+ NF < 3 { next } # skip malformed
+ $1 == td {
+ printf("%s %d\n", $3, $2 + 1)
+ }
+' "$F_BDAY_RECORDS")
+
+[ -z "$BDAY_LIST" ] && exit 0
+
+magick -size 800x600 canvas:black \
+ -gravity north -font 'Adwaita-Sans-Bold' -pointsize 72 -fill white \
+ -annotate +0+50 'Birthdays Today' \
+ -gravity center -font 'Adwaita-Sans' -pointsize 36 \
+ -annotate +0+100 "$BDAY_LIST" \
+ ~/Digital/Pictures/Backgrounds/birthday.png
+
+awk -v td="$today" '
+ /^# last run:/ { next } # drop old last-run
+ $0 ~ /^[[:space:]]*#/ { print; next } # preserve other comments
+ NF < 3 { print; next } # preserve blanks/malformed
+ $1 == td { $2 = $2 + 1 } # bump age
+ { print $1, $2, $3 } # print all records
+' "$F_BDAY_RECORDS" > bdays.tmp
+
+echo "# last run: $run_date" >> bdays.tmp
+mv bdays.tmp "$F_BDAY_RECORDS"
+
+xwallpaper --output HDMI-A-0 --center "$BDAY_IMG"