-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
rec2org
executable file
·58 lines (42 loc) · 1.34 KB
/
rec2org
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
#!/usr/bin/env sh
######################################################################
# @author : Gavin Jaeger-Freeborn ([email protected])
# @file : rec2org.sh
# @created : Wed 23 Sep 2020 11:19:30 AM
#
# @description :
######################################################################
ORGTEMPLATE="* {{State}} {{Name}} :{{Class}}:
SCHEDULED: <{{Scheduled}}>
DEADLINE: <{{Deadline}}> {{Desc}}
"
DATE=$(date)
RECORGFILE="${HOME}/Documents/org/rec.org"
RECFILE="${HOME}/schedule.rec"
formatDates()
{
# recsel -s '' -e "Scheduled >> \"${DATE}\"|| Deadline >> \"${DATE}\" || State = 'TODO'" ${HOME}/schedule.rec |
# Check that the file is properly formatted
recfix --check "${RECFILE}" || exit 1
# Process one line at a time.
recsel "${RECFILE}" |
while IFS=': ' read -r key val
do
# multi line
if [ "$key" = '+' ];then
printf "%s %s\n" "$key" "$val"
continue
fi
# End of an entry
[ -z "$key" ] && echo "" && continue
# date
if [ "$key" = 'Scheduled' ] || [ "$key" = 'Deadline' ] ; then
val="$(date +'%Y-%m-%d %a %H:%M' --date "$val")"
fi
printf "%s: %s\n" "$key" "$val"
done
}
formatDates |
recfmt "$ORGTEMPLATE" |
sed -E -e '/(DEADLINE: <>|SCHEDULED: <>)/d' -e 's/::$//g' > $RECORGFILE
# vim: set tw=78 ts=2 et sw=2 sr: