commit e94c325b59f3beabc2ff363a87a897cdd48eb18e parent ad970a40786d99ebecd1b3cbaab4b0f10c7c23da Author: Anders Damsgaard <anders@adamsgaard.dk> Date: Fri, 3 Apr 2020 15:14:37 +0200 Offer to add ical events to calendar Diffstat:
M | .local/bin/plumb | | | 42 | +++++++++++++++++++++++++++++++++++++----- |
1 file changed, 37 insertions(+), 5 deletions(-)
diff --git a/.local/bin/plumb b/.local/bin/plumb @@ -2,6 +2,7 @@ set -e version=0.1 +calendar="$HOME/.calendar/calendar" show_help() { echo "usage: ${0##*/} [OPTIONS] [FILE|URL]" @@ -63,6 +64,40 @@ annotate_date_string() { sed 's/^\([0-9][0-9][0-9][0-9]\)\([0-1][0-9]\)\([0-3][0-9]\)/\1-\2-\3 /;s/T\([0-2][0-9]\)\([0-5][0-9]\)\([0-5][0-9]\)/\1:\2:\3/' } +handle_calendar_invite() { + starttime="$(grep -E "DTSTART.*TZID" "$1" | sed 's/.*://' | annotate_date_string )" + endtime="$(grep -E "DTEND.*TZID" "$1" | sed 's/.*://' | annotate_date_string )" + tzone="$(grep -E "DTEND.*TZID" "$1" | sed 's/.*TZID=\(.*\):.*/\1/' )" + summary="$(grep -E "SUMMARY.*:" "$1" | sed 's/.*: *//' )" + + printf 'start time: %s\n' "$starttime" + printf 'end time: %s\n' "$endtime" + printf 'time zone: %s\n' "$tzone" + printf 'summary: %s\n' "$summary" + + printf 'add to calendar? [y/N] ' + read -r $REPLY + case "$REPLY" in + Y|y|YES|Yes|yes|myes) + month="$(printf '%s' "$starttime" | sed 's/.*-\([0-1][0-9]\)-[0-3][0-9].*/\1/')" + day="$(printf '%s' "$starttime" | sed 's/.*-[0-1][0-9]-\([0-3][0-9]\).*/\1/')" + hour_start="$(printf '%s' "$starttime" | sed 's/.* \([0-2][0-9]\):[0-5][0-9].*/\1/')" + min_start="$(printf '%s' "$starttime" | sed 's/.* [0-2][0-9]:\([0-5][0-9]\).*/\1/')" + hour_end="$(printf '%s' "$endtime" | sed 's/.* \([0-2][0-9]\):[0-5][0-9].*/\1/')" + min_end="$(printf '%s' "$endtime" | sed 's/.* [0-2][0-9]:\([0-5][0-9]\).*/\1/')" + printf '%s/%s\t%s:%s-%s:%s %s (%s)\n' "$month" "$day" \ + "$hour_start" "$min_start" "$hour_end" "$min_end" \ + "$summary" "$tzone" \ + >> "$calendar" + rsync "$calendar" adamsgaard.dk:~/.calendar + upload "$calendar" >/dev/null;; + *) exit;; + esac + + #notify-send "$1" "$(printf 'start: %s\nend: %s\n%s' "$starttime" "$endtime" "$tzone")" + #termopen less "$1" +} + handle_target() { t="$1" @@ -77,11 +112,8 @@ handle_target() { detach $BROWSER "$t";; text/*) if [ "$(file -b "$t")" = "vCalendar calendar file" ]; then - starttime="$(grep -E "DTSTART.*TZID" "$t" | sed 's/.*://' | annotate_date_string )" - endtime="$(grep -E "DTEND.*TZID" "$t" | sed 's/.*://' | annotate_date_string )" - tzone="$(grep -E "DTEND.*TZID" "$t" | sed 's/.*TZID=\(.*\):.*/\1/' )" - notify-send "$t" "$(printf 'start: %s\nend: %s\n%s' "$starttime" "$endtime" "$tzone")" - termopen less "$t" + handle_calendar_invite "$t" + else termopen less "$t" fi;;