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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
#!/bin/bash
#state variable that determines if the main loop is running
loop=true
#time of next update
nexttime=$(date +%s)
#intervals between updates in seconds
interval=60
#time before an starts before a notification pops up
remind=900
#gets username and password
read -p "username:" caluser
export caluser
read -s -p "password:" calpass
echo ""
export calpass
#This has to be done at the beginning of every run of the script now, don't know
#why, but if it isn't then vdirsyncer sync will refuse to run
vdirsyncer discover
#help message
echo "Beginning to sync up caledar files, type \"q\" + enter to quit,
\"s\" + enter to sync now,
\"k\" + enter to launch khal in interactive mode,
and \"a\" + enter to list agenda"
while [ "$loop" == true ]; do
#w/ timeout of 1, read input
read -t 1 input
#handles quit, this is run at every loop and pretty much determines how
#slow the loop runs
if [ "$input" == "q" ]; then
loop=false
fi
if [ "$input" == "k" ]; then
khal interactive
#in case anything was editted
nexttime=$(date +%s)
fi
if [ "$input" == "a" ]; then
khal calendar
fi
if [ "$input" == "s" ]; then
nexttime=$(date +%s)
fi
#If the current time is greater than the next scheduled update, update
if [ $(date +%s) -ge $nexttime ]; then
echo starting sync at $(date +%s)
#syncs with remote calDAV server
vdirsyncer sync
#stores the old list of upcoming events so that we can compare
#after updating, this will create an error on the first run but
#this doesn't matter
mv ~/.vdirsyncer/events ~/.vdirsyncer/oldevents
#updates khal and also list any upcoming events
#determines in seconds the interval of time that khal limits
#itself to when looking for events (their start times have have
#to fall within this interval)
window=$(( (interval) * 3 ))s
#determines the time which khal is actually querying, this
#should be now + remind before time, window does not matter
#because we're testing for when an event passes out of the
#interval
testtime=$(( $(date +%s) + $remind ))
#now get the properly formated string representing the above
#time in a way khal understands
#Note: The below only works if the time format is set to be the
#same way in khal's config
timestring=$(date --date="@$testtime" "+%m/%d/%Y %I:%M %p")
echo Testing for upcoming events at $timestring
#writes upcoming events to events file to be diffed later
khal list $now $timestring --once --notstarted >> ~/.vdirsyncer/events
#checks to see if any changes in the upcoming events queue
#exists by diff'ing oldevents and events, then finding what was
#removed
difference=$(diff ~/.vdirsyncer/oldevents ~/.vdirsyncer/events | grep "<")
#only when an event is exiting the test interval do we care, so
#if $difference is "< No events" or empty, then we say that
# an event entered the interval or no change occured
#Schedules the next update, keeps adding $interval until we get
#one that's actually in the future, since it's not guaranteed
#that each update will take less than 1 $interval to run
if [ "$difference" == "" ]; then
echo No changes in upcoming events
elif [ "$difference" == "< No events" ]; then
echo an event entered the test interval
else
echo an event has exited the test interval
notify-send "$difference"
fi
while [ $(date +%s) -ge $nexttime ]; do
nexttime=$(( $nexttime + $interval))
done
echo next sync scheduled at $nexttime
fi
done
|