Skip to content

Instantly share code, notes, and snippets.

@metacoma
Created February 20, 2016 10:53
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metacoma/a1c64acdfcd45d8d7049 to your computer and use it in GitHub Desktop.
Save metacoma/a1c64acdfcd45d8d7049 to your computer and use it in GitHub Desktop.
#!/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
@mschaaf
Copy link

mschaaf commented Apr 12, 2016

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.

@mschaaf
Copy link

mschaaf commented Apr 13, 2016

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