report.sh
2.3 KB
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
#!/bin/zsh
source $0:A:h/datetimehelper.sh
source $0:A:h/taskhelper.sh
source $0:A:h/ttyhelper.sh
function tasksallsince() {
[[ $# -lt 1 ]] && return 1
taskuuids \(\(\( +COMPLETED or +DELETED \) end.after:${1} \) \
or +PENDING \) $@
}
function datetimedescription() {
[[ $# -lt 1 ]] && return 1
for UUID in $(tasksallsince $@)
do
DESCRIPTION="$(taskdescription $UUID)"
PROJECT="$(taskproject $UUID)"
COMPLETED="$(taskuuids $UUID \( +COMPLETED or +DELETED \))"
for T in $(tasktimes $UUID)
do
extracttime $T
printf "%s;%s;%s;%s;%s\n" \
"$TIMEKEY" "$TIME" "$PROJECT" "$DESCRIPTION" "$COMPLETED"
done
done
}
function report() {
[[ $# -lt 1 ]] && return 1
local D DATE T
DATE=$1
for LINE in "${(f)$(datetimedescription $@|sort -t\; -f -k1,1 -k3,3)}"
do
set -- "${(@s(;))LINE}"
if [[ -n $1 && $(date -d $1 +%s) -ge $(date -d $DATE +%s) ]]
then
if [[ $D != $1 ]]
then
D=$1
printf "%s\n" $(underline "" $D)
fi
T=$2
if [[ -n $5 ]] && T=$(bold "" $T)
if [[ -n $D ]] && printf "%s [%s] - %s\n" "$T" "$3" "$4"
fi
done
}
function usage() {
local USAGE=$(cat <<-USAGE
Usage: %s [-?] [DATETIME] [FILTER]
OPTIONS:
-?, --help Show this help
-d, --date DATETIME is a date and time identifier as accepted by the
date command. It specifies how long back done tasks
should be considered.
FILTER can be additional taskwarriors filters to limit the result
any further.
USAGE
)
/usr/bin/printf "${USAGE}\n" $0
}
#
# parse command line arguments
#
SHORTOPTS=?d:
LONGOPTS=help,date
ARGS=$(getopt -o ${SHORTOPTS} --long ${LONGOPTS} -n report -- $@)
if [ $? -ne 0 ]
then
usage $0
exit 1
fi
eval set -- ${=ARGS}
unset ARGS
while true
do
case $1 in
'-?'|'--help')
shift
usage $0
exit 0
;;
'-d'|'--date')
DATEFROM=$(date -d ${2} +%Y-%m-%d)
shift 2
continue
;;
'--')
shift
break
;;
*)
echo 'Internal error!' >&2
exit 1
;;
esac
done
DATEFROM=${DATEFROM:-$(date +%Y-%m-01)}
report $DATEFROM $@
# vim: set et ts=4 sw=4: