blob: da23973e54d7ed3c9d7c23bdc523458796b40c56 (
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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
|