dotfiles/.local/bin/statusbar/sb-appointments

40 lines
1.7 KiB
Plaintext
Raw Normal View History

#!/bin/sh
#Print the next appointment for the day for statusbar
#or generate notification for upcoming appointment
2023-10-12 15:12:12 +02:00
notify_mins_before=10
calcurse -a | perl -pe 's/([0-9]{2}:[0-9]{2})\n/\1/' | tail -n+2 | perl -pe 's/^\s*-\s*([0-9]{2}:[0-9]{2})\s*->\s*([0-9]{2}:[0-9]{2})\s*(.*?)$/\1\t\2\t\3/' |
while read -r appointment; do
start=$(echo "$appointment" | cut -d'\t' -f1)
end=$(echo "$appointment" | cut -d'\t' -f2)
description=$(echo "$appointment" | cut -d'\t' -f3)
done
2020-12-24 11:53:05 +01:00
diff=$(calcurse --next | sed -n 's/^\s*//; s/\[//;s/\]//p' | cut -f1 -d ' ' | perl -pe 's/0([0-9])/\1/g' )
2020-12-15 14:40:40 +01:00
if [ -n "$diff" ]; then
secs=$(( $(echo "$diff" | cut -f1 -d ':') * 3600 + $(echo "$diff" | cut -f2 -d ':') *60 ))
time_appointment="$(date --date "@$(( $( date +'%s' ) + $secs ))" +"%s")"
appointment="$(calcurse --next | tail -n1 | awk '{$1=""; print $0}' | sed 's/^\s*//')"
#shorten lecture appointments to just the name of lecture without profs
if [ "${#appointment}" -gt 20 ]; then
appointment="$(echo "$appointment" | sed -E 's/\(([VUG])\).*/(\1)/')"
fi
2020-12-15 14:40:40 +01:00
if [ "$1" = "notif" ]; then
msg="$(printf '%s\n%s' "$(date --date "@$time_appointment" +'%H:%M')" "$appointment")"
2023-10-12 15:12:12 +02:00
check_for_notif "$msg"
2020-12-15 14:40:40 +01:00
notify-send "Appointment coming up" "$msg"
2023-10-12 15:12:12 +02:00
printf "%s\n%s\n" $(date -I) $msg >> /tmp/apts_notif
2020-12-15 14:40:40 +01:00
else
2023-10-12 15:12:12 +02:00
#Fix this ugly thing lmao
2020-12-15 14:40:40 +01:00
midnight=$(( $(date --date "$(date | sed 's/..:..:../23:59:59/; s/ PM//; s/ AM//')" +%s) + 1 ))
if [ $midnight -gt "$time_appointment" ]; then
2021-06-12 18:27:40 +02:00
#only print appointment if dunst-notifications are also shown -> "privacy screen"
if [ ! -f /tmp/nodunst ]; then
printf '%s %s' "$(date --date "@$time_appointment" +'%H:%M')" "$appointment"
fi
2020-12-15 14:40:40 +01:00
fi
fi
fi
printf '\n'