dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit 7fea0b8657604685c458dacb46434cb5bddceef4
parent b6679656e39479a46b4a013e619731898e2273ac
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Mon,  2 Nov 2020 19:38:59 +0100

add preliminary calendar-export

the output does not appear to be fully up to rfc5545 specs yet

Diffstat:
A.local/bin/calendar-export | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 67 insertions(+), 0 deletions(-)

diff --git a/.local/bin/calendar-export b/.local/bin/calendar-export @@ -0,0 +1,67 @@ +#!/bin/sh +# parse calendar(1) output to iCalendar (.ics) format +# NOTE: assumes all events occur in current year + +calfile="$HOME/.calendar/calendar" +year="$(date '+%Y')" + +die() +{ + printf '%s: error: %s\n' "${0##*/}" "$1" >&2 + exit 1 +} + +if test ! -r "$calfile"; then + die "calendar file $calfile does not exist" +fi + +ical_header() +{ + printf 'BEGIN:VCALENDAR\r\n' + printf 'VERSION:2.0\r\n' + printf 'PRODID:-//%s//calendar-export:2.0\r\n' "$(whoami)" + printf 'X-WR-TIMEZONE:Etc/GMT\r\n' +} + +ical_footer() +{ + printf 'END:VCALENDAR\r\n' +} + +ical_event() +{ + datestr="$(printf '%s' "$1" | cut -d' ' -f1)" + case "$datestr" in + Jan\ *) month=01;; + Feb\ *) month=02;; + Mar\ *) month=03;; + Apr\ *) month=04;; + May\ *) month=05;; + Jun\ *) month=06;; + Jul\ *) month=07;; + Aug\ *) month=08;; + Sep\ *) month=09;; + Oct\ *) month=10;; + Nov\ *) month=11;; + Dec\ *) month=12;; + *) die "could not extract month from $1";; + esac + date="$(printf '%s' "$datestr" | sed 's/.*\([0-3][0-9]\).*/\1/')" + desc="$(printf '%s' "$1" | cut -d' ' -f2-)" + + printf 'BEGIN:VEVENT\r\n' + printf 'UID:none@none.com\r\n' + printf 'DTSTAMP:19970610T172345Z\r\n' + printf 'DTSTART:%s%s%s\r\n' "$year" "$month" "$date" + printf 'DTEND:%s%s%s\r\n' "$year" "$month" "$date" + printf 'SUMMARY:%s\r\n' "$desc" + printf 'END:VEVENT\r\n' +} + +ical_header + +calendar -f "$calfile" -B 365 -A 365 | awk '!x[$0]++' | while read -r; do + ical_event "$REPLY" +done + +ical_footer