Showing
2 changed files
with
164 additions
and
1 deletions
timesheet/original.sh
0 → 100755
1 | +#!/bin/bash | |
2 | +# File : timesheet.sh | |
3 | +# | |
4 | +# This generates timesheet data for my fedora ${TASK}s only | |
5 | +#exec 2>/dev/null | |
6 | + | |
7 | +WHICH='/usr/bin/which' | |
8 | +DATE="$(${WHICH} date)" | |
9 | +PRINTF="$(${WHICH} printf)" | |
10 | +ECHO="$(${WHICH} echo)" | |
11 | +SED="$(${WHICH} sed)" | |
12 | +TASK="$(${WHICH} task)" | |
13 | +HEAD="$(${WHICH} head)" | |
14 | +ANSI2HTML="$(${WHICH} ansi2html)" | |
15 | + | |
16 | +phrase="1-weeks-ago" | |
17 | +fmt="%Y-%m-%d" | |
18 | +start=$(${DATE} +$fmt -d $phrase) | |
19 | +end=$(${DATE} +$fmt) | |
20 | +filter='' | |
21 | + | |
22 | +function usage() | |
23 | +{ | |
24 | + echo "${0} [OPTIONS] [PROJECT]" | |
25 | + echo | |
26 | + echo "Get a timesheet for the past last week." | |
27 | + echo "The \"spent\" time is the whole time spent with this task." | |
28 | + echo | |
29 | + echo "OPTIONS:" | |
30 | + printf " %10s : %s\n" '-?' 'Get this help message.' | |
31 | + printf " %10s : %s\n" '-h' 'Write HTML instead of ansi console text.' | |
32 | + printf " %10s : %s\n" '-o path' 'Save the date under a file defined by' | |
33 | + printf " %10s %s\n" '' '"path" preceeded by the current date and time' | |
34 | + printf " %10s %s\n" '' 'and an ".html" suffix.' | |
35 | + echo | |
36 | + echo "PROJECT:" | |
37 | + echo " The project to create the timesheet for." | |
38 | +} | |
39 | + | |
40 | +OUTFILE='' | |
41 | +TO_HTML=0 | |
42 | + | |
43 | +while getopts 'o:h?' opt | |
44 | +do | |
45 | + case $opt in | |
46 | + o) | |
47 | + OUTFILE="${OPTARG}";; | |
48 | + h) | |
49 | + TO_HTML=1;; | |
50 | + ?) | |
51 | + usage | |
52 | + exit 0;; | |
53 | + *) | |
54 | + usage | |
55 | + exit 1;; | |
56 | + esac | |
57 | +done | |
58 | + | |
59 | +shift $((${OPTIND} - 1)) | |
60 | + | |
61 | +test ${1} && filter="project.is:${1}" | |
62 | + | |
63 | +function taskdata() | |
64 | +{ | |
65 | + echo "$(${TASK} $@ | ${SED} '1,3d' | ${HEAD} -n -2)" | |
66 | +} | |
67 | + | |
68 | +function display() | |
69 | +{ | |
70 | + ${ECHO} | |
71 | + ${ECHO} -en "\033[4mproject \033[24m " | |
72 | + ${ECHO} -en "\033[4mdescription \033[24m " | |
73 | + ${ECHO} -en "\033[4mcompleted \033[24m " | |
74 | + ${ECHO} -en "\033[4mentered \033[24m " | |
75 | + ${ECHO} -e "\033[4mspent \033[24m" | |
76 | + for i in $* | |
77 | + do | |
78 | + project="$(taskdata uuid:${i} project)" | |
79 | + local description="$(taskdata uuid:${i} description)" | |
80 | + local end="$(taskdata uuid:${i} end)" | |
81 | + local entry="$(taskdata uuid:${i} entry)" | |
82 | + 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')" | |
83 | + | |
84 | + project="$(${PRINTF} "%.15s" "${project}")" | |
85 | + description="$(${PRINTF} "%.35s" "${description}")" | |
86 | + | |
87 | + local years=0 | |
88 | + local months=0 | |
89 | + local days=0 | |
90 | + local hours=0 | |
91 | + local minutes=0 | |
92 | + local seconds=0 | |
93 | + for t in ${times} | |
94 | + do | |
95 | + ta=(${t//:/ }) | |
96 | + hours=$((hours+$((10#${ta[0]})))) | |
97 | + minutes=$((minutes+$((10#${ta[1]})))) | |
98 | + seconds=$((seconds+$((10#${ta[2]})))) | |
99 | + done | |
100 | + minutes=$((minutes+$((seconds/60)))) | |
101 | + seconds=$((seconds%60)) | |
102 | + hours=$((hours+$((minutes/60)))) | |
103 | + minutes=$((minutes%60)) | |
104 | + | |
105 | + ${PRINTF} "% -15s % -35s % -10s % -10s %02d:%02d:%02d\n" \ | |
106 | + "${project}" "${description}" "${end}" \ | |
107 | + "${entry}" "${hours}" "${minutes}" "${seconds}" | |
108 | + done | |
109 | + ${ECHO} | |
110 | +} | |
111 | + | |
112 | +function timesheet() | |
113 | +{ | |
114 | + ${ECHO} " (generated at $(date))" | |
115 | + ${ECHO} | |
116 | + ${ECHO} -e "\033[1mTasks completed from $start to $end (back $phrase)\033[22m" | |
117 | + display $(taskdata uuid ${filter} end.after:$start) | |
118 | + | |
119 | + ${ECHO} | |
120 | + ${ECHO} -e "\033[1mUpcoming tasks\033[22m" | |
121 | + display $(taskdata uuidnext ${filter}) | |
122 | + | |
123 | + ${ECHO} | |
124 | + ${ECHO} -e "\033[1mBlocked tasks\033[22m" | |
125 | + ${TASK} blocked $filter rc._forcecolor=on | |
126 | + | |
127 | + ${ECHO} | |
128 | + ${ECHO} -e "\033[1mBlocking tasks\033[22m" | |
129 | + ${TASK} blocking $filter rc._forcecolor=on | |
130 | + | |
131 | + ${ECHO} | |
132 | + ${ECHO} -e "\033[1mSummary\033[22m" | |
133 | + ${TASK} summary $filter rc._forcecolor=on | |
134 | + | |
135 | + ${ECHO} | |
136 | + ${ECHO} -e "\033[1mHistory\033[22m" | |
137 | + ${TASK} history $filter rc._forcecolor=on | |
138 | + ${TASK} ghistory $filter rc._forcecolor=on | |
139 | + ${ECHO} -e "\n" | |
140 | + ${TASK} burndown.daily rc._forcecolor=on | |
141 | + ${ECHO} -e "\n" | |
142 | + ${TASK} burndown rc._forcecolor=on | |
143 | +} | |
144 | + | |
145 | +if [ ${OUTFILE} ] | |
146 | +then | |
147 | + OUTFILE="${OUTFILE}_$(${DATE} +"%Y-%m-%d_%H:%M:%S")" | |
148 | + if [ ${TO_HTML} -ne 0 ] | |
149 | + then | |
150 | + timesheet $@ | ${ANSI2HTML} >${OUTFILE}.html | |
151 | + else | |
152 | + timesheet $@ >${OUTFILE} | |
153 | + fi | |
154 | +else | |
155 | + if [ ${TO_HTML} -ne 0 ] | |
156 | + then | |
157 | + timesheet $@ | ${ANSI2HTML} | |
158 | + else | |
159 | + timesheet $@ | |
160 | + fi | |
161 | +fi | |
162 | + | |
163 | +# vim: set ft=sh ts=4 sw=4: | ... | ... |
Please
register
or
login
to post a comment