Created
February 20, 2016 10:53
-
-
Save metacoma/a1c64acdfcd45d8d7049 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
PATH=${PATH}:/usr/local/bin/ | |
calendar_get_events() { | |
local day="${1:-tomorrow}" # see man date(1) DATE STRING | |
# validate day syntax | |
for i in $day "$day + 1 day"; do | |
date -d"${i}" "+%Y-%m-%d" >/dev/null 2>&1 || { | |
echo "calendar_get_events invalid argument, see man date(1) DATE STRING" > /dev/stderr | |
return | |
} | |
done | |
gcalcli --military --nocolor agenda `date -d"$day" +%Y-%m-%d` `date -d"$day + 1 day" +%Y-%m-%d` | |
} | |
parse_events() { | |
sed -E 's/^..\. [^\.]+\. [0-9]+? //' | awk -r '/^ +[0-9]+?:[0-9]+? / {printf "[CAL] "$1;$1=""; print $0}' | sort -r | |
} | |
habatica_update_todo() { | |
xargs -tI% sh -c "habitica todos | fgrep '%' || habitica todos add --difficulty=easy '%'" | |
} | |
calendar_get_events "now" | parse_events | habatica_update_todo |
The parse_events function did not work perfectly it always misses the first event of a day. The following line fixes it for me sed -E 's/^.*? [0-9]+?^C//' | awk -r '/^.*[0-9]+?:[0-9]+? / {printf "[CAL] "$1;$1=""; print $0}' | sort -r$
. Replace the existing line in the method parse_events with the one before.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you have access to shared calendars you should consider to specify a calendar on line 16 with the calendar option like
--calendar <calendar name here>
. If not all events from all calendars will be imported.