summaryrefslogtreecommitdiff
path: root/pim/rc/show
diff options
context:
space:
mode:
authorCalvin Morrison <calvin@pobox.com>2026-08-22 13:16:49 -0400
committerCalvin Morrison <calvin@pobox.com>2026-08-22 13:16:49 -0400
commit8a3d2c99bff60cb775ebc42516c0c3912d54ba3d (patch)
treefd136a3b7927146763cdc11e6be07c71f92bb92c /pim/rc/show
parent9aacce8b3b54060d0037eca897856d7273e6e5e8 (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/show')
-rwxr-xr-xpim/rc/show115
1 files changed, 115 insertions, 0 deletions
diff --git a/pim/rc/show b/pim/rc/show
new file mode 100755
index 0000000..da23973
--- /dev/null
+++ b/pim/rc/show
@@ -0,0 +1,115 @@
+#!/bin/rc
+# pim/show -- everything known about one event.
+#
+# Takes a path to an occurrence under events/date/, as printed by
+# "pim/agenda -p" or plumbed from a window, or a pattern to search for.
+rfork e
+
+mtpt=/mnt/pim
+days=90
+all=()
+only=()
+
+while(~ $1 -*){
+ switch($1){
+ case -m
+ mtpt=$2; shift
+ case -n
+ days=$2; shift
+ case -a
+ all=1
+ case -c
+ only=($only $2); shift
+ case *
+ echo 'usage: show [-m mtpt] [-n days] [-c cal] [-a] path|pattern' >[1=2]
+ exit usage
+ }
+ shift
+}
+if(~ $#* 0){
+ echo 'usage: show [-m mtpt] [-n days] [-c cal] [-a] path|pattern' >[1=2]
+ exit usage
+}
+pat=$"*
+
+fn field {
+ sed -n 's/^'^$2^': //p' $1
+}
+
+fn one {
+ f=$1
+ d=`{basename -d $f}
+ sum=`{field $f summary}
+ echo $"sum
+ echo $"sum | sed 's/./-/g'
+ ep=`{field $f epoch}
+ ee=`{field $f epochend}
+ if(~ $#ep 0)
+ sed -n 's/^start: /when /p' $f
+ if(! ~ $#ep 0){
+ # backquotes give a list and ^ distributes over it; flatten first
+ w=`{date -f 'WWW DD MMM YYYY hh:mm' $"ep}
+ x=`{date -f hh:mm $"ee}
+ echo 'when '^$"w^'-'^$"x
+ }
+ sed -n 's/^location: /where /p' $f
+ sed -n 's/^rrule: /repeats /p' $f
+ ev=`{field $f event}
+ if(! ~ $#ev 0){
+ e=$d/$"ev
+ if(test -f $e/organizer){
+ o=`{cat $e/organizer}
+ echo 'from '^$"o
+ }
+ if(test -f $e/attendees){
+ echo who
+ sed 's/^/ /' $e/attendees
+ }
+ echo 'event '^`{cleanname $"e}
+ }
+ echo 'at '^$"f
+ # a blank line ends the header; the rest is the description
+ sed -n '/^$/,$p' $f | sed 1d
+}
+
+fn search {
+ cals=$only
+ if(~ $#cals 0)
+ cals=`{pim/calendars -m $mtpt}
+ now=`{date -n}
+ i=0
+ while(test $i -lt $days){
+ 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)
+ grep -li '^summary: .*'^$"pat $d/* >[2]/dev/null
+ }
+ i=`{echo $i + 1 | bc}
+ }
+}
+
+if(test -f $"pat){
+ one $"pat
+ exit 0
+}
+
+hits=`{search}
+if(~ $#hits 0){
+ echo 'pim/show: nothing matching '^$"pat^' in the next '^$"days^' days' >[1=2]
+ exit notfound
+}
+if(! ~ $#all 0){
+ for(h in $hits){
+ one $h
+ echo
+ }
+ exit 0
+}
+one $hits(1)
+if(test $#hits -gt 1){
+ echo
+ echo '('^`{echo $#hits - 1 | bc}^' more; -a for all)'
+}
+exit 0