dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit f977c39f915d78f71ec018726b3f58bf8fe031f4
parent eb1b0b9e7b4f28921e205a01ec762c18cedba964
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Wed,  6 May 2020 09:31:47 +0200

Add calendar notification script

Diffstat:
A.local/bin/calendar-notify | 31+++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+), 0 deletions(-)

diff --git a/.local/bin/calendar-notify b/.local/bin/calendar-notify @@ -0,0 +1,31 @@ +#!/bin/sh +# send upcoming events to notification daemon +# crontab line: +# */15 * * * * export DISPLAY=:0; calendar-notify + +regexmatch() { + printf '%s' "$1" | grep -E -q "$2" +} + +t_notify=1800 +t_now="$(date +%s)" + +calendar -A 0 | while read -r month day time desc; do + + day="$(printf '%s' "$day" | sed 's/\*$//')" + + if ! regexmatch "$time" "[0-2]*[0-9]:[0-5][0-9]"; then + desc="${time} ${desc}" + time="" + fi + + if [ -n "$time" ]; then + hour="$(printf '%s' "$time" | sed 's/\([0-2]*[0-9]\):.*/\1/')" + min="$(printf '%s' "$time" | sed 's/[0-2]*[0-9]:\([0-5][0-9]\).*/\1/')" + t="$(date -j +%s "$(date +%Y%m)${day}${hour}${min}")" + + if [ $(( $t - $t_now )) -le "$t_notify" ]; then + notify-send "${desc}" "${time}" + fi + fi +done