summaryrefslogtreecommitdiff
path: root/calwrapper
diff options
context:
space:
mode:
Diffstat (limited to 'calwrapper')
-rwxr-xr-xcalwrapper93
1 files changed, 93 insertions, 0 deletions
diff --git a/calwrapper b/calwrapper
new file mode 100755
index 0000000..da0a46c
--- /dev/null
+++ b/calwrapper
@@ -0,0 +1,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