original.sh
3.77 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
#!/bin/bash
# File : timesheet.sh
#
# This generates timesheet data for my fedora ${TASK}s only
#exec 2>/dev/null
WHICH='/usr/bin/which'
DATE="$(${WHICH} date)"
PRINTF="$(${WHICH} printf)"
ECHO="$(${WHICH} echo)"
SED="$(${WHICH} sed)"
TASK="$(${WHICH} task)"
HEAD="$(${WHICH} head)"
ANSI2HTML="$(${WHICH} ansi2html)"
phrase="1-weeks-ago"
fmt="%Y-%m-%d"
start=$(${DATE} +$fmt -d $phrase)
end=$(${DATE} +$fmt)
filter=''
function usage()
{
echo "${0} [OPTIONS] [PROJECT]"
echo
echo "Get a timesheet for the past last week."
echo "The \"spent\" time is the whole time spent with this task."
echo
echo "OPTIONS:"
printf " %10s : %s\n" '-?' 'Get this help message.'
printf " %10s : %s\n" '-h' 'Write HTML instead of ansi console text.'
printf " %10s : %s\n" '-o path' 'Save the date under a file defined by'
printf " %10s %s\n" '' '"path" preceeded by the current date and time'
printf " %10s %s\n" '' 'and an ".html" suffix.'
echo
echo "PROJECT:"
echo " The project to create the timesheet for."
}
OUTFILE=''
TO_HTML=0
while getopts 'o:h?' opt
do
case $opt in
o)
OUTFILE="${OPTARG}";;
h)
TO_HTML=1;;
?)
usage
exit 0;;
*)
usage
exit 1;;
esac
done
shift $((${OPTIND} - 1))
test ${1} && filter="project.is:${1}"
function taskdata()
{
echo "$(${TASK} $@ | ${SED} '1,3d' | ${HEAD} -n -2)"
}
function display()
{
${ECHO}
${ECHO} -en "\033[4mproject \033[24m "
${ECHO} -en "\033[4mdescription \033[24m "
${ECHO} -en "\033[4mcompleted \033[24m "
${ECHO} -en "\033[4mentered \033[24m "
${ECHO} -e "\033[4mspent \033[24m"
for i in $*
do
project="$(taskdata uuid:${i} project)"
local description="$(taskdata uuid:${i} description)"
local end="$(taskdata uuid:${i} end)"
local entry="$(taskdata uuid:${i} entry)"
local times="$(${TASK} uuid:${i} info | ${SED} '/duration/{;s/.*duration: PT\(\([0-9]\+\)H\)\?\(\([0-9]\+\)M\)\?\(\([0-9]\+\)S\)\?.*/\2:\4:\6/;s/^:/0:/;s/::/:0:/;s/:$/:0/;p;};d')"
project="$(${PRINTF} "%.15s" "${project}")"
description="$(${PRINTF} "%.35s" "${description}")"
local years=0
local months=0
local days=0
local hours=0
local minutes=0
local seconds=0
for t in ${times}
do
ta=(${t//:/ })
hours=$((hours+$((10#${ta[0]}))))
minutes=$((minutes+$((10#${ta[1]}))))
seconds=$((seconds+$((10#${ta[2]}))))
done
minutes=$((minutes+$((seconds/60))))
seconds=$((seconds%60))
hours=$((hours+$((minutes/60))))
minutes=$((minutes%60))
${PRINTF} "% -15s % -35s % -10s % -10s %02d:%02d:%02d\n" \
"${project}" "${description}" "${end}" \
"${entry}" "${hours}" "${minutes}" "${seconds}"
done
${ECHO}
}
function timesheet()
{
${ECHO} " (generated at $(date))"
${ECHO}
${ECHO} -e "\033[1mTasks completed from $start to $end (back $phrase)\033[22m"
display $(taskdata uuid ${filter} end.after:$start)
${ECHO}
${ECHO} -e "\033[1mUpcoming tasks\033[22m"
display $(taskdata uuidnext ${filter})
${ECHO}
${ECHO} -e "\033[1mBlocked tasks\033[22m"
${TASK} blocked $filter rc._forcecolor=on
${ECHO}
${ECHO} -e "\033[1mBlocking tasks\033[22m"
${TASK} blocking $filter rc._forcecolor=on
${ECHO}
${ECHO} -e "\033[1mSummary\033[22m"
${TASK} summary $filter rc._forcecolor=on
${ECHO}
${ECHO} -e "\033[1mHistory\033[22m"
${TASK} history $filter rc._forcecolor=on
${TASK} ghistory $filter rc._forcecolor=on
${ECHO} -e "\n"
${TASK} burndown.daily rc._forcecolor=on
${ECHO} -e "\n"
${TASK} burndown rc._forcecolor=on
}
if [ ${OUTFILE} ]
then
OUTFILE="${OUTFILE}_$(${DATE} +"%Y-%m-%d_%H:%M:%S")"
if [ ${TO_HTML} -ne 0 ]
then
timesheet $@ | ${ANSI2HTML} >${OUTFILE}.html
else
timesheet $@ >${OUTFILE}
fi
else
if [ ${TO_HTML} -ne 0 ]
then
timesheet $@ | ${ANSI2HTML}
else
timesheet $@
fi
fi
# vim: set ft=sh ts=4 sw=4: