calendar-notify (945B)
1 #!/bin/sh 2 # send upcoming events to notification daemon 3 # crontab line: 4 # */15 * * * * export DISPLAY=:0; calendar-notify 5 6 regexmatch() { 7 printf '%s' "$1" | grep -E -q "$2" 8 } 9 10 t_notify=1000 11 t_now="$(date +%s)" 12 13 calendar -A 0 | while read -r month day time desc; do 14 15 day="$(printf '%s' "$day" | sed 's/\*$//')" 16 17 if ! regexmatch "$time" "[0-2]*[0-9]:[0-5][0-9]"; then 18 desc="${time} ${desc}" 19 time="" 20 fi 21 22 if [ -n "${time}" ]; then 23 hour="$(printf '%s' "$time" | sed 's/\([0-2]*[0-9]\):.*/\1/')" 24 if [ "$(printf '%s' "$hour" | wc -c)" -lt 2 ]; then 25 hour="0${hour}" 26 fi 27 min="$(printf '%s' "$time" | sed 's/[0-2]*[0-9]:\([0-5][0-9]\).*/\1/')" 28 29 if [ "$(uname)" = OpenBSD ]; then 30 t="$(date -j +%s "$(date +%Y%m)${day}${hour}${min}")" 31 else 32 t="$(date -d "$(date +%Y-%m)-${day} ${hour}:${min}" +%s)" 33 fi 34 35 dt="$(( $t - $t_now ))" 36 if [ "$dt" -le "$t_notify" ] && [ "$dt" -ge 0 ]; then 37 xmessage "$desc" "$time" 38 fi 39 fi 40 done