1 files changed, 43 insertions(+), 0 deletions(-)

A => importicals
A => importicals +43 -0
@@ 0,0 1,43 @@ 
+#!/bin/bash
+
+CALDIR=$HOME/.calendars
+DDIR=$XDG_DATA_HOME/remind
+mkdir -p "$DDIR"
+FOUT="$DDIR/reminders"
+
+function help() {
+	printf "USAGE: $0 <command>\n"
+	printf "  import -- reload DB from %s\n" "$CALDIR"
+	printf "  watch  -- watch %s for new events and import them\n" "$CALDIR"
+	exit $1
+}
+
+case $1 in
+	import)
+		rm -f "$FOUT"
+		for dir in $(find $CALDIR -maxdepth 1 -mindepth 1 -type d -print)
+		do
+			LABEL=$(basename $dir)
+			printf "Processing %s\n " "$LABEL"
+			bar -c "ical2rem --label ${LABEL}" -o "$FOUT" $dir/*.ics
+		done
+		;;
+	watch)
+		# fswatch regex inclusion is broken
+		fswatch ~/.calendars --event Created --event IsFile --recursive |\
+		while read -r event; do
+			# because of the fswatch bug, we have to check this the hard way
+			echo "$event" | grep -qP '^.*\.ics$'
+			if [[ $? -eq 0 ]]; then
+				LABEL=$(basename "$event")
+				cat "$event" | ical2rem --label ${LABEL} >> "$FOUT"
+			fi
+		done
+		;;
+	help)
+		help 0
+		;;
+	*)
+		help 1
+		;;
+esac