diff options
| author | Calvin Morrison <calvin@pobox.com> | 2026-08-22 13:16:49 -0400 |
|---|---|---|
| committer | Calvin Morrison <calvin@pobox.com> | 2026-08-22 13:16:49 -0400 |
| commit | 8a3d2c99bff60cb775ebc42516c0c3912d54ba3d (patch) | |
| tree | fd136a3b7927146763cdc11e6be07c71f92bb92c /pim/rc/next | |
| parent | 9aacce8b3b54060d0037eca897856d7273e6e5e8 (diff) | |
pim: personal information management, starting with a calendar
A calendar as a file tree, and tools that only know the tree:
events/date/yyyy/mm/dd/hhmm-summary as lived
events/uuid/<uid>/ as stored
ctl query alarm changed
lib/cal owns all of that. A backend supplies events and, where its
protocol allows, takes changes back -- six methods. cmd/icalfs is the
first: it reads .ics files from a directory and nothing else, because
fetching is rc/fetch's job and hget already exists. That keeps
net/http out of the binary and makes a subscribed calendar and a local
one the same thing.
The tools are rc on purpose. If the tree needs a compiled program to be
useful, the tree is the wrong shape. Three things were added to the
tree because the rc port needed them: a path from an occurrence to its
event, epoch seconds beside RFC3339, and a numeric slot for all-day
events so test(1) can compare it.
ctl reports caps, so a tool can say "read only" instead of trying and
failing. A published .ics is read only: nowhere to PUT, and no
METHOD:REQUEST to reply to. CalDAV would be read write rsvp schedule,
and that is the next backend.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'pim/rc/next')
| -rwxr-xr-x | pim/rc/next | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/pim/rc/next b/pim/rc/next new file mode 100755 index 0000000..0436cb3 --- /dev/null +++ b/pim/rc/next @@ -0,0 +1,81 @@ +#!/bin/rc +# pim/next -- the next thing, one line, for a window label. +rfork e + +# test(1) reads a leading zero as octal: 0700 compares as 448 and 0900 +# is a syntax error. Strip the padding before any arithmetic. +fn num { + echo $1 | sed 's/^0*//; s/^$/0/' +} + +mtpt=/mnt/pim +only=() +while(~ $1 -*){ + switch($1){ + case -m + mtpt=$2; shift + case -c + only=($only $2); shift + case * + echo 'usage: next [-m mtpt] [-c cal]' >[1=2] + exit usage + } + shift +} +cals=$only +if(~ $#cals 0) + cals=`{pim/calendars -m $mtpt} + +now=`{date -n} +hhmm=`{num `{date -f hhmm $now}} +tmp=/tmp/next.$pid +fn sigexit { rm -f $tmp } + +i=0 +while(test $i -lt 14){ + sec=`{echo $now + $i '*' 86400 | bc} + day=`{date -f YYYY/MM/DD $sec} + { + for(c in $cals){ + d=$mtpt/calendars/$c/events/date/$day + if(test -d $d) + for(f in $d/*){ + b=`{basename $f} + sum=`{sed -n 's/^summary: //p' $f} + echo $"b^' '^$"c^' '^$"sum + } + } + } | sort >$tmp + if(test -s $tmp){ + day='' + if(test $i -gt 0){ + d=`{date -f 'WWW DD MMM' $sec} + day=$"d^' ' + } + # awk prints the finished line: a value carried back through + # an rc variable would be split on its tabs and rejoined + # with spaces + out=/tmp/next.out.$pid + awk -F' ' -v 'first='^$i -v 'now='^$"hhmm -v 'day='^$"day ' + { + t = $1 + 0 + if (first > 0 || t >= now) { + split($1, a, "-") + when = substr(a[1],1,2) ":" substr(a[1],3,2) + if ($1 ~ /^0000-allday-/) + when = "all day" + printf "%s%s %s\n", day, when, $3 + exit + } + }' $tmp >$out + if(test -s $out){ + cat $out + rm -f $out $tmp + exit 0 + } + rm -f $out + } + i=`{echo $i + 1 | bc} +} +echo 'nothing scheduled' +exit 0 |
