aboutsummaryrefslogtreecommitdiff
path: root/scripts/sdep-checknow
blob: 4771957e4bd1f60d4bbf5ca7d49d7f771bbadaf5 (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
#!/bin/sh

# Run this every minute (for example using cron) to receive a notification
# when an event happens.
#
# The events are read from the following files in $sdepdata folder:
#	once: events that only happen once; full date needs to be specified
#	daily: events that happen every day; only specify the time in HH:MM format
#	weekly: only specify Weekday + time
#	monthly: only specify day of the month + time

# Requires: a command to send notifications such as herbe or notify-send.
# The weekly part uses the non-portable -d option of GNU date, which you
# might have to change if you are not on Linux (on some systems you can
# accomplish the same with -j).

sdepdata="${XDG_DATA_HOME:-$HOME/.local/share}/sdep"

#notify="notify-send -t 3600000"
notify=herbe
title="$(date +%H:%M)"

sdepnotify() {
	sdep -w "" -s "" | while read text; do $notify "$title" "$text"; done
}

# One-off events
sdepnotify <"$sdepdata/once"

# Daily events
sed "s/^/$(date +%Y-%m-%d) /" <"$sdepdata/daily" | sdepnotify 

# Weekly events - needs GNU date (try -j intead of -d on BSD)
while read line; do
	weekday=$(echo "$line" | sed "s/ .*$//")
	echo "$line" | sed "s/^[ ]*[^ ]* /$(date -d $weekday +%Y-%m-%d) /"
done <"$sdepdata/weekly" | \
sdepnotify

# Monthly events
sed "s/^[ ]*/$(date +%Y-%m-)/" <"$sdepdata/daily" | sdepnotify 

Generated with cgit - Back to sebastiano.tronto.net