aboutsummaryrefslogtreecommitdiff
path: root/scripts/sdep-list
blob: c1e89f9caa44519bd867c134d43ebd5917dc6e7f (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh

# Lists events happening in a specific time range.
# Recurring events are listed at most once, and only if their first occurrence
# is in the range.
#
# The events are read from the following files in the $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

# This script uses relies on the non-portable -d option of GNU date.

# Usage: sdep-list [today|tomorrow|week|nextweek|past|future]
# No options = all

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

from=""
to=""
w="%d %b %H:%M"

case $1 in
	today)
		from="$(date +%Y-%m-%d) 0:00"
		to="$(date +%Y-%m-%d) 23:59"
		w="%H:%M"
		;;
	tomorrow)
		from="$(date -d tomorrow +%Y-%m-%d) 0:00"
		to="$(date -d tomorrow +%Y-%m-%d) 23:59"
		w="%H:%M"
		;;
	week)
		from="$(date -d 'last monday' +%Y-%m-%d) 0:00"
		to="$(date -d sunday +%Y-%m-%d) 23:59"
		w="%a %H:%M"
		;;
	nextweek)
		from="$(date -d 'next monday' +%Y-%m-%d) 0:00"
		to="$(date -d 'next monday + 6 days' +%Y-%m-%d) 23:59"
		w="%a %H:%M"
		;;
	past)
		to="$(date +'%Y-%m-%d %H:%M')"
		;;
	future)
		from="$(date +'%Y-%m-%d %H:%M')"
		;;
	*)
		;;
esac

tempfile=$(mktemp)

cat "$sdepdata/once" > "$tempfile"
sed "s/^/$(date +%Y-%m-%d) /" <"$sdepdata/daily" | >> "$tempfile"
while read line; do
	weekday=$(echo "$line" | sed "s/ .*$//")
	echo "$line" | sed "s/^[ ]*[^ ]* /$(date -d $weekday +%Y-%m-%d) /"
done <"$sdepdata/weekly" >> "$tempfile"
sed "s/^[ ]*/$(date +%Y-%m-)/" <"$sdepdata/daily" >> "$tempfile"

sdep -w "$w" -f "$from" -t "$to" <"$tempfile"

rm "$tempfile"

Generated with cgit - Back to sebastiano.tronto.net