summaryrefslogtreecommitdiff
path: root/pim/rc/find
blob: 8ee162abaa647d4f4c399c5786a33585c43c1e35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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