aboutsummaryrefslogtreecommitdiff
path: root/scripts/util/bday.sh
blob: 72ac5563a02ddbedf6bd8f6400b2ae66676bec5c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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"