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