Commit 5a966fc39145434519d4383eb21e8c68f8170d8d
1 parent
8f2fe2bb
fix missing newline and add option handling and file io
Showing
1 changed file
with
93 additions
and
12 deletions
| @@ -57,7 +57,7 @@ function taskend() { | @@ -57,7 +57,7 @@ function taskend() { | ||
| 57 | function taskuuids() { | 57 | function taskuuids() { |
| 58 | local UUID | 58 | local UUID |
| 59 | 59 | ||
| 60 | - [[ $# -eq 0 ]] && set \( +PENDING or +DONE \) | 60 | + [[ $# -eq 0 ]] && set -- \( +PENDING or +DONE \) |
| 61 | for UUID in $(task $@ _uuid) | 61 | for UUID in $(task $@ _uuid) |
| 62 | do | 62 | do |
| 63 | printf "%05.2f\037%s\037%s\n" \ | 63 | printf "%05.2f\037%s\037%s\n" \ |
| @@ -113,7 +113,7 @@ function extracttime() { | @@ -113,7 +113,7 @@ function extracttime() { | ||
| 113 | TIME="00:00:00" | 113 | TIME="00:00:00" |
| 114 | else | 114 | else |
| 115 | IFS=: | 115 | IFS=: |
| 116 | - set $(echo $1) | 116 | + set -- $(echo $1) |
| 117 | IFS=${OIFS} | 117 | IFS=${OIFS} |
| 118 | TIMEKEY="$1" | 118 | TIMEKEY="$1" |
| 119 | TIME=$(printf "%02d:%02d:%02d" ${2:-0} ${3:-0} $4) | 119 | TIME=$(printf "%02d:%02d:%02d" ${2:-0} ${3:-0} $4) |
| @@ -125,7 +125,7 @@ function printtimes() { | @@ -125,7 +125,7 @@ function printtimes() { | ||
| 125 | for T in "$@" | 125 | for T in "$@" |
| 126 | do | 126 | do |
| 127 | extracttime "$T" | 127 | extracttime "$T" |
| 128 | - printf "%51s: %s\n" "spent - $TIMEKEY" $TIME | 128 | + printf "%51s: %s\n" "spent - $TIMEKEY" "$TIME" |
| 129 | done | 129 | done |
| 130 | } | 130 | } |
| 131 | 131 | ||
| @@ -165,20 +165,29 @@ function showall() { | @@ -165,20 +165,29 @@ function showall() { | ||
| 165 | } | 165 | } |
| 166 | 166 | ||
| 167 | function timesheet() { | 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)" | 168 | + local PHRASE="1-week-ago" |
| 169 | + local START="$(date +%Y-%m-%d -d ${PHRASE})" | ||
| 170 | + | ||
| 171 | + local DONE="$(showall $(doneuuids end.after:${START} $@))" | ||
| 172 | + local UPCOMING="$(showall $(pendinguuids $@))" | ||
| 173 | + local BLOCKED="$(showall $(blockeduuids $@))" | ||
| 174 | + local BLOCKING="$(showall $(blockinguuids $@))" | ||
| 175 | + | ||
| 176 | + DONE="${DONE:+${DONE}${NL}}" | ||
| 177 | + UPCOMING="${UPCOMING:+${UPCOMING}${NL}}" | ||
| 178 | + BLOCKED="${BLOCKED:+${BLOCKED}${NL}}" | ||
| 179 | + BLOCKING="${BLOCKING:+${BLOCKING}${NL}}" | ||
| 171 | 180 | ||
| 172 | printf " (generated at %s)\n\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n" \ | 181 | 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} $@))" \ | 182 | + "${TODAY}" \ |
| 183 | + "$(bold "" "Tasks completed from $START to $TODAY (back $PHRASE)")" \ | ||
| 184 | + "${DONE}" \ | ||
| 176 | "$(bold "" "Upcoming tasks")" \ | 185 | "$(bold "" "Upcoming tasks")" \ |
| 177 | - "$(showall $(pendinguuids $@))" \ | 186 | + "${UPCOMING}" \ |
| 178 | "$(bold "" "Blocked tasks")" \ | 187 | "$(bold "" "Blocked tasks")" \ |
| 179 | - "$(showall $(blockeduuids $@))" \ | 188 | + "${BLOCKED}" \ |
| 180 | "$(bold "" "Blocking tasks")" \ | 189 | "$(bold "" "Blocking tasks")" \ |
| 181 | - "$(showall $(blockinguuids $@))" | 190 | + "${BLOCKING}" |
| 182 | 191 | ||
| 183 | printf "%s%s\n\n%s%s\n%s\n\n%s\n\n%s\n" \ | 192 | printf "%s%s\n\n%s%s\n%s\n\n%s\n\n%s\n" \ |
| 184 | "$(bold "" "Summary")" \ | 193 | "$(bold "" "Summary")" \ |
| @@ -190,6 +199,78 @@ function timesheet() { | @@ -190,6 +199,78 @@ function timesheet() { | ||
| 190 | "$(task rc._forcecolor=on $@ burndown 2>/dev/null)" | 199 | "$(task rc._forcecolor=on $@ burndown 2>/dev/null)" |
| 191 | } | 200 | } |
| 192 | 201 | ||
| 202 | +function usage() { | ||
| 203 | + local USAGE=$(cat <<-USAGE | ||
| 204 | + Usage: %s [OPTION]... [FILTER] | ||
| 205 | + | ||
| 206 | + OPTIONS: | ||
| 207 | + -?, --help Show this help | ||
| 208 | + -h, --html Create HTML form ANSI data. | ||
| 209 | + -f, --file The file to write data to. Actually this specifies the | ||
| 210 | + basename which will be postfixed by the creation date. | ||
| 211 | + | ||
| 212 | + FILTER can be additional taskwarriors filters to limit the result | ||
| 213 | + any further. | ||
| 214 | + USAGE | ||
| 215 | + ) | ||
| 216 | + /usr/bin/printf "${USAGE}\n" $0 | ||
| 217 | +} | ||
| 218 | + | ||
| 219 | +TODAY="$(date +%Y-%m-%d)" | ||
| 220 | +NL=$'\n' | ||
| 221 | + | ||
| 222 | +# | ||
| 223 | +# parse command line arguments | ||
| 224 | +# | ||
| 225 | +SHORTOPTS=?hf: | ||
| 226 | +LONGOPTS=help,html,file | ||
| 227 | +ARGS=$(getopt -o "${SHORTOPTS}" --long "${LONGOPTS}" -n "timesheet" -- "$@") | ||
| 228 | +if [ $? -ne 0 ] | ||
| 229 | +then | ||
| 230 | + usage "$0" | ||
| 231 | + exit 1 | ||
| 232 | +fi | ||
| 233 | +eval set -- "${ARGS}" | ||
| 234 | +unset ARGS | ||
| 235 | + | ||
| 236 | +while true | ||
| 237 | +do | ||
| 238 | + case "$1" in | ||
| 239 | + '-?'|'--help') | ||
| 240 | + shift | ||
| 241 | + usage "$0" | ||
| 242 | + exit 0 | ||
| 243 | + ;; | ||
| 244 | + '-h'|'--html') | ||
| 245 | + DOHTML=1 | ||
| 246 | + shift | ||
| 247 | + continue | ||
| 248 | + ;; | ||
| 249 | + '-f'|'--file') | ||
| 250 | + OUTFILE="${2}_$TODAY" | ||
| 251 | + shift 2 | ||
| 252 | + continue | ||
| 253 | + ;; | ||
| 254 | + '--') | ||
| 255 | + shift | ||
| 256 | + break | ||
| 257 | + ;; | ||
| 258 | + *) | ||
| 259 | + echo 'Internal error!' >&2 | ||
| 260 | + exit 1 | ||
| 261 | + ;; | ||
| 262 | + esac | ||
| 263 | +done | ||
| 264 | + | ||
| 265 | +[[ $OUTFILE ]] && { | ||
| 266 | + if [[ ${DOHTML} -eq 1 ]] | ||
| 267 | + then | ||
| 268 | + exec 1> >(ansi2html >${OUTFILE}.html) | ||
| 269 | + else | ||
| 270 | + exec 1> ${OUTFILE}.ansi | ||
| 271 | + fi | ||
| 272 | +} | ||
| 273 | + | ||
| 193 | timesheet $@ | 274 | timesheet $@ |
| 194 | 275 | ||
| 195 | # vim: set et ts=4 sw=4: | 276 | # vim: set et ts=4 sw=4: |
Please
register
or
login
to post a comment