summaryrefslogtreecommitdiff
path: root/pim/rc/find
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/find
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/find')
-rwxr-xr-xpim/rc/find77
1 files changed, 77 insertions, 0 deletions
diff --git a/pim/rc/find b/pim/rc/find
new file mode 100755
index 0000000..8ee162a
--- /dev/null
+++ b/pim/rc/find
@@ -0,0 +1,77 @@
+#!/bin/rc
+# pim/find -- ask every calendar a question, by attribute.
+#
+# pim/find attendee michael
+# pim/find summary standup from 2026-08-19 to 2026-08-26
+# pim/find -c work attendee michael
+#
+# Attributes are separate words, as ndb/query takes them: rc lexes a bare
+# attr=value as an assignment, so it cannot be an argument unquoted.
+rfork e
+
+mtpt=/mnt/pim
+long=()
+only=()
+
+while(~ $1 -*){
+ switch($1){
+ case -m
+ mtpt=$2; shift
+ case -c
+ only=($only $2); shift
+ case -l
+ long=1
+ case *
+ echo 'usage: find [-m mtpt] [-c cal] [-l] attr value ...' >[1=2]
+ exit usage
+ }
+ shift
+}
+if(~ $#* 0){
+ echo 'usage: find [-m mtpt] [-c cal] [-l] attr value ...' >[1=2]
+ exit usage
+}
+
+q=()
+while(! ~ $#* 0){
+ switch($1){
+ case '*=*'
+ q=($q $1)
+ shift
+ case *
+ if(~ $#* 1){
+ echo 'pim/find: '^$1^' has no value' >[1=2]
+ exit usage
+ }
+ q=($q $1^'='^$2)
+ shift; shift
+ }
+}
+
+cals=$only
+if(~ $#cals 0)
+ cals=`{pim/calendars -m $mtpt}
+
+# the server answers with paths relative to its own root, since it
+# cannot know where it was mounted
+hits=()
+for(c in $cals){
+ echo $q >$mtpt/calendars/$c/query
+ for(r in `{cat $mtpt/calendars/$c/query})
+ hits=($hits $mtpt/calendars/$c/$r)
+}
+
+if(~ $#hits 0)
+ exit 0
+if(~ $#long 0){
+ for(h in $hits)
+ echo $h
+ exit 0
+}
+for(h in $hits){
+ ep=`{sed -n 's/^epoch: //p' $h}
+ sum=`{sed -n 's/^summary: //p' $h}
+ when=`{date -f 'WWW DD MMM YYYY hh:mm' $"ep}
+ echo $"when^' '^$"sum
+}
+exit 0