#!/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