timesheet.sh
4.26 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/zsh
function tasktimes() {
[[ $# -eq 0 ]] && return 1
local KEY=${2:-\\1}
local T
local D='([0-9]{4}-[0-9]{2}-[0-9]{2})'
local N='([0-9]+)'
local EXPR='s/'$D'.*PT('$N'H)?('$N'M)?('$N').*/'${KEY}':\3:\5:\7/;te;d;:e'
task $1 info | sed -r ${EXPR} | awk -F: '
{
s = (d[$1][2] + $4) % 60
_m = int((d[$1][2] + $4) / 60)
m = (d[$1][1] + $3 + _m) % 60
_h = int((d[$1][1] + $3 + _m) / 60)
d[$1][0] += $2 + _h
d[$1][1] = m
d[$1][2] = s
}
END {
for(i in d)
printf("%s:%d:%d:%d\n", i, d[i][0], d[i][1], d[i][2])
}'
}
function tasktimestotal() {
tasktimes $1 TOTAL
}
function taskdescription() {
[[ $# -eq 0 ]] && return 1
task $1 _unique description
}
function taskproject() {
[[ $# -eq 0 ]] && return 1
task $1 _unique project
}
function taskurgency() {
[[ $# -eq 0 ]] && return 1
task $1 _urgency | cut -d\ -f 4
}
function taskentry() {
[[ $# -eq 0 ]] && return 1
task $1 _unique entry
}
function taskend() {
[[ $# -eq 0 ]] && return 1
task $1 _unique end
}
function taskuuids() {
local UUID
[[ $# -eq 0 ]] && set \( +PENDING or +DONE \)
for UUID in $(task $@ _uuid)
do
printf "%05.2f\037%s\037%s\n" \
"$(taskurgency $UUID)" \
"$(taskdescription $UUID)" \
$UUID
done | sort -t$'\037' -k1nr,2 | cut -d$'\037' -f3
}
function pendinguuids() {
taskuuids +PENDING $@
}
function doneuuids() {
taskuuids +DONE $@
}
function blockeduuids() {
taskuuids +BLOCKED $@
}
function blockinguuids() {
taskuuids +BLOCKING $@
}
function deleteduuids() {
taskuuids +DELETED $@
}
function underline() {
[[ $# -lt 2 ]] && return 1
printf "\033[4m%${1}s\033[24m" "$2"
}
function bold() {
[[ $# -lt 2 ]] && return 1
printf "\033[1m%${1}s\033[22m" "$2"
}
function tstodate() {
[[ $# -eq 0 ]] && return 1
date -d @${1} +%Y-%m-%d
}
function extracttime() {
[[ $# -eq 0 ]] && return 1
local OIFS=${IFS}
if [[ -z $1 ]]
then
TIMEKEY=""
TIME="00:00:00"
else
IFS=:
set $(echo $1)
IFS=${OIFS}
TIMEKEY="$1"
TIME=$(printf "%02d:%02d:%02d" ${2:-0} ${3:-0} $4)
fi
}
function printtimes() {
local T
for T in "$@"
do
extracttime "$T"
printf "%51s: %s\n" "spent - $TIMEKEY" $TIME
done
}
function truncate() {
[[ $# -lt 2 ]] && return 1
local STRING=$1
[[ ${#STRING} -gt ${2} ]] && STRING="${STRING:0:$(($2-3))}..."
echo -n "${STRING}"
}
function showall() {
[[ $# -eq 0 ]] && return 1
local T UUID OIFS
printf "%s %s %s %s %s\n" \
"$(underline -16 project)" \
"$(underline -35 description)" \
"$(underline -8 spent)" \
"$(underline -10 completed)" \
"$(underline -10 entered)"
for UUID in "$@"
do
extracttime "$(tasktimes $UUID TOTAL)"
printf "%-16s %-35s %-10s %-10s %-8s\n" \
"$(truncate "$(taskproject $UUID)" 16)" \
"$(truncate "$(taskdescription $UUID)" 35)" \
"$TIME" \
"$(tstodate $(taskend $UUID))" \
"$(tstodate $(taskentry $UUID))" \
printtimes $(tasktimes $UUID)
done
}
function timesheet() {
local phrase="1-week-ago"
local start="$(date +%Y-%m-%d -d ${phrase})"
local end="$(date +%Y-%m-%d)"
printf " (generated at %s)\n\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n" \
"$(date)" \
"$(bold "" "Tasks completed from $start to $end (back $phrase)")" \
"$(showall $(doneuuids end.after:${start}))" \
"$(bold "" "Upcoming tasks")" \
"$(showall $(pendinguuids))" \
"$(bold "" "Blocked tasks")" \
"$(showall $(blockeduuids))" \
"$(bold "" "Blocking tasks")" \
"$(showall $(blockinguuids))"
printf "%s%s\n\n%s%s\n%s\n\n%s\n\n%s\n" \
"$(bold "" "Summary")" \
"$(task summary rc._forcecolor=on 2>/dev/null)" \
"$(bold "" "History")" \
"$(task history rc._forcecolor=on 2>/dev/null)" \
"$(task ghistory rc._forcecolor=on 2>/dev/null)" \
"$(task burndown.daily rc._forcecolor=on 2>/dev/null)" \
"$(task burndown rc._forcecolor=on 2>/dev/null)"
}
timesheet
# vim: set et ts=4 sw=4: