Commit fc876698be1866eb4f850945a4210e4c140ba018
1 parent
c36e36bc
Add script for getting timesheets from taskwarrior
Showing
1 changed file
with
195 additions
and
0 deletions
timesheet/timesheet.sh
0 → 100755
1 | +#!/bin/zsh | ||
2 | + | ||
3 | +function tasktimes() { | ||
4 | + [[ $# -eq 0 ]] && return 1 | ||
5 | + | ||
6 | + local KEY=${2:-\\1} | ||
7 | + local T | ||
8 | + local D='([0-9]{4}-[0-9]{2}-[0-9]{2})' | ||
9 | + local N='([0-9]+)' | ||
10 | + local EXPR='s/'$D'.*PT('$N'H)?('$N'M)?('$N').*/'${KEY}':\3:\5:\7/;te;d;:e' | ||
11 | + | ||
12 | + task $1 info | sed -r ${EXPR} | awk -F: ' | ||
13 | + { | ||
14 | + s = (d[$1][2] + $4) % 60 | ||
15 | + _m = int((d[$1][2] + $4) / 60) | ||
16 | + m = (d[$1][1] + $3 + _m) % 60 | ||
17 | + _h = int((d[$1][1] + $3 + _m) / 60) | ||
18 | + d[$1][0] += $2 + _h | ||
19 | + d[$1][1] = m | ||
20 | + d[$1][2] = s | ||
21 | + } | ||
22 | + END { | ||
23 | + for(i in d) | ||
24 | + printf("%s:%d:%d:%d\n", i, d[i][0], d[i][1], d[i][2]) | ||
25 | + }' | ||
26 | +} | ||
27 | + | ||
28 | +function tasktimestotal() { | ||
29 | + tasktimes $1 TOTAL | ||
30 | +} | ||
31 | + | ||
32 | +function taskdescription() { | ||
33 | + [[ $# -eq 0 ]] && return 1 | ||
34 | + task $1 _unique description | ||
35 | +} | ||
36 | + | ||
37 | +function taskproject() { | ||
38 | + [[ $# -eq 0 ]] && return 1 | ||
39 | + task $1 _unique project | ||
40 | +} | ||
41 | + | ||
42 | +function taskurgency() { | ||
43 | + [[ $# -eq 0 ]] && return 1 | ||
44 | + task $1 _urgency | cut -d\ -f 4 | ||
45 | +} | ||
46 | + | ||
47 | +function taskentry() { | ||
48 | + [[ $# -eq 0 ]] && return 1 | ||
49 | + task $1 _unique entry | ||
50 | +} | ||
51 | + | ||
52 | +function taskend() { | ||
53 | + [[ $# -eq 0 ]] && return 1 | ||
54 | + task $1 _unique end | ||
55 | +} | ||
56 | + | ||
57 | +function taskuuids() { | ||
58 | + local UUID | ||
59 | + | ||
60 | + [[ $# -eq 0 ]] && set \( +PENDING or +DONE \) | ||
61 | + for UUID in $(task $@ _uuid) | ||
62 | + do | ||
63 | + printf "%05.2f\037%s\037%s\n" \ | ||
64 | + "$(taskurgency $UUID)" \ | ||
65 | + "$(taskdescription $UUID)" \ | ||
66 | + $UUID | ||
67 | + done | sort -t$'\037' -k1nr,2 | cut -d$'\037' -f3 | ||
68 | +} | ||
69 | + | ||
70 | +function pendinguuids() { | ||
71 | + taskuuids +PENDING $@ | ||
72 | +} | ||
73 | + | ||
74 | +function doneuuids() { | ||
75 | + taskuuids +DONE $@ | ||
76 | +} | ||
77 | + | ||
78 | +function blockeduuids() { | ||
79 | + taskuuids +BLOCKED $@ | ||
80 | +} | ||
81 | + | ||
82 | +function blockinguuids() { | ||
83 | + taskuuids +BLOCKING $@ | ||
84 | +} | ||
85 | + | ||
86 | +function deleteduuids() { | ||
87 | + taskuuids +DELETED $@ | ||
88 | +} | ||
89 | + | ||
90 | +function underline() { | ||
91 | + [[ $# -lt 2 ]] && return 1 | ||
92 | + printf "\033[4m%${1}s\033[24m" "$2" | ||
93 | +} | ||
94 | + | ||
95 | +function bold() { | ||
96 | + [[ $# -lt 2 ]] && return 1 | ||
97 | + printf "\033[1m%${1}s\033[22m" "$2" | ||
98 | +} | ||
99 | + | ||
100 | +function tstodate() { | ||
101 | + [[ $# -eq 0 ]] && return 1 | ||
102 | + date -d @${1} +%Y-%m-%d | ||
103 | +} | ||
104 | + | ||
105 | +function extracttime() { | ||
106 | + [[ $# -eq 0 ]] && return 1 | ||
107 | + | ||
108 | + local OIFS=${IFS} | ||
109 | + | ||
110 | + if [[ -z $1 ]] | ||
111 | + then | ||
112 | + TIMEKEY="" | ||
113 | + TIME="00:00:00" | ||
114 | + else | ||
115 | + IFS=: | ||
116 | + set $(echo $1) | ||
117 | + IFS=${OIFS} | ||
118 | + TIMEKEY="$1" | ||
119 | + TIME=$(printf "%02d:%02d:%02d" ${2:-0} ${3:-0} $4) | ||
120 | + fi | ||
121 | +} | ||
122 | + | ||
123 | +function printtimes() { | ||
124 | + local T | ||
125 | + for T in "$@" | ||
126 | + do | ||
127 | + extracttime "$T" | ||
128 | + printf "%51s: %s\n" "spent - $TIMEKEY" $TIME | ||
129 | + done | ||
130 | +} | ||
131 | + | ||
132 | +function truncate() { | ||
133 | + [[ $# -lt 2 ]] && return 1 | ||
134 | + | ||
135 | + local STRING=$1 | ||
136 | + | ||
137 | + [[ ${#STRING} -gt ${2} ]] && STRING="${STRING:0:$(($2-3))}..." | ||
138 | + echo -n "${STRING}" | ||
139 | +} | ||
140 | + | ||
141 | +function showall() { | ||
142 | + [[ $# -eq 0 ]] && return 1 | ||
143 | + | ||
144 | + local T UUID OIFS | ||
145 | + | ||
146 | + printf "%s %s %s %s %s\n" \ | ||
147 | + "$(underline -16 project)" \ | ||
148 | + "$(underline -35 description)" \ | ||
149 | + "$(underline -8 spent)" \ | ||
150 | + "$(underline -10 completed)" \ | ||
151 | + "$(underline -10 entered)" | ||
152 | + | ||
153 | + for UUID in "$@" | ||
154 | + do | ||
155 | + extracttime "$(tasktimes $UUID TOTAL)" | ||
156 | + printf "%-16s %-35s %-10s %-10s %-8s\n" \ | ||
157 | + "$(truncate "$(taskproject $UUID)" 16)" \ | ||
158 | + "$(truncate "$(taskdescription $UUID)" 35)" \ | ||
159 | + "$TIME" \ | ||
160 | + "$(tstodate $(taskend $UUID))" \ | ||
161 | + "$(tstodate $(taskentry $UUID))" \ | ||
162 | + | ||
163 | + printtimes $(tasktimes $UUID) | ||
164 | + done | ||
165 | +} | ||
166 | + | ||
167 | +function timesheet() { | ||
168 | + local phrase="1-week-ago" | ||
169 | + local start="$(date +%Y-%m-%d -d ${phrase})" | ||
170 | + local end="$(date +%Y-%m-%d)" | ||
171 | + | ||
172 | + printf " (generated at %s)\n\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n" \ | ||
173 | + "$(date)" \ | ||
174 | + "$(bold "" "Tasks completed from $start to $end (back $phrase)")" \ | ||
175 | + "$(showall $(doneuuids end.after:${start}))" \ | ||
176 | + "$(bold "" "Upcoming tasks")" \ | ||
177 | + "$(showall $(pendinguuids))" \ | ||
178 | + "$(bold "" "Blocked tasks")" \ | ||
179 | + "$(showall $(blockeduuids))" \ | ||
180 | + "$(bold "" "Blocking tasks")" \ | ||
181 | + "$(showall $(blockinguuids))" | ||
182 | + | ||
183 | + printf "%s%s\n\n%s%s\n%s\n\n%s\n\n%s\n" \ | ||
184 | + "$(bold "" "Summary")" \ | ||
185 | + "$(task summary rc._forcecolor=on 2>/dev/null)" \ | ||
186 | + "$(bold "" "History")" \ | ||
187 | + "$(task history rc._forcecolor=on 2>/dev/null)" \ | ||
188 | + "$(task ghistory rc._forcecolor=on 2>/dev/null)" \ | ||
189 | + "$(task burndown.daily rc._forcecolor=on 2>/dev/null)" \ | ||
190 | + "$(task burndown rc._forcecolor=on 2>/dev/null)" | ||
191 | +} | ||
192 | + | ||
193 | +timesheet | ||
194 | + | ||
195 | +# vim: set et ts=4 sw=4: |
Please
register
or
login
to post a comment