-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate_repeating
executable file
·67 lines (58 loc) · 1.43 KB
/
update_repeating
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
#!/bin/sh -u
# Copyright (C) 2009-2017 Serge Hallyn <[email protected]>
BASEDIR=$(dirname $0)
if [ -z "${BASEDIR}" -o "${BASEDIR}" = "." ]; then
BASEDIR=$(pwd)
fi
cd "${BASEDIR}"
fmt() {
printf "%02d" $1
}
usage() {
echo "$0 [all]: update tickler entries"
echo "If \"all\" is specified, update entries before today as well"
exit 0
}
if [ $# -gt 0 ]; then
if [ "$1" = "-h" -o "$1" = "--help" -o "$1" = "help" ]; then
usage
elif [ "$1" = "all" ]; then
export TICKLER_DOALL="yes"
fi
fi
# Tickler entries are inserted between 'XXX'. So on each
# run, delete all such lines, but keep other (presumably
# inserted by the user) entries.
# Do the .bak dance for the old sed on macos.
for i in `seq 1 31`; do
f=$(fmt $i)
mv $f $f.bak
sed -e '/^XXX.*XXX$/d' $f.bak > $f
done
month=`date +%m`
list=`cal | tail -2`
numdays=`for i in $list; do echo $i; done | tail -1`
# get the list of repeating/ files
filelist=`/bin/ls repeating/`
for f in $filelist; do
echo reading file repeating/$f
grep "^A " repeating/$f > nextlist
cat nextlist | while read line; do
./insert_entry.py $line
done
grep "^W " repeating/$f > nextlist
cat nextlist | while read line; do
./insert_entry.py $line
done
grep "^D " repeating/$f > nextlist
cat nextlist | while read line; do
./insert_entry.py $line
done
grep "^M " repeating/$f > nextlist
cat nextlist | while read line; do
./insert_entry.py $line
done
done
rm nextlist
rm *.bak
date +%m > lastrun