Commit ba3541b9a5a0fe4dc3ee25ce43378e8feb1b8674

Authored by Georg Hopp
1 parent 0246eab5

Pretty the output

1 1 function todate() {
2 2 [[ $# -eq 0 ]] && return 1
3   - date -d ${1} +%Y-%m-%d
  3 + date -d ${1} +%d.%m.%Y
4 4 }
5 5
6 6 function tstodate() {
... ...
... ... @@ -8,44 +8,65 @@ source $0:A:h/ttyhelper.sh
8 8 function showall() {
9 9 [[ $# -eq 0 ]] && return 1
10 10
11   - local T UUID OIFS WORK FIRST
  11 + local T UUID OIFS WORK NO
12 12
13 13 printf "%s %s %s %s %s\n" \
14   - "$(underline -16 project)" \
15   - "$(underline -35 description)" \
  14 + "$(underline -10 project)" \
  15 + "$(underline -33 description)" \
16 16 "$(underline -13 spent)" \
17 17 "$(underline -10 completed)" \
18 18 "$(underline -10 entered)"
19 19
20 20 for UUID in $@
21 21 do
22   - FIRST=true
  22 + NO=1
23 23
24   - flattened_work ${UUID}|\
25   - jq -M -r 'map([.[]]|@sh)|join("\n")'|\
26   - while read WORK; do
27   - eval set -- ${WORK}
  24 + WORK="$(flattened_work ${UUID}|jq -M -r 'map([.[]]|@sh)|join("\n")')"
  25 + UNITS=$(echo ${WORK}|wc -l)
  26 + echo "${WORK}"|while read W; do
  27 + eval set -- ${W}
28 28
29   - if ${FIRST}; then
  29 + if [[ ${NO} -eq 1 ]]; then
30 30 local TIME="$(formattime $4)"
31 31 local PROJECT="$(task _get $UUID.project)"
32 32
33   - printf "%-16s %-35s %13s %-10s %-10s\n" \
34   - "$(truncate "${PROJECT:-(none)}" 16)" \
  33 + printf "%-10.10s %-33.33s %s %-10.10s %-10.10s\n" \
  34 + "$(truncate "${PROJECT:-(none)}" 12)" \
35 35 "$(truncate "$(task _get $UUID.description)" 35)" \
36   - "$(bold "" "${TIME}")" \
  36 + "$(bold "13" "${TIME}")" \
37 37 "$(todate $(task _get $UUID.end))" \
38 38 "$(todate $(task _get $UUID.entry))"
39 39 fi
40 40
41   - printf "%50s: %14s\n" \
42   - "$(date -u -d "$1" +%c)" \
43   - "$(formattime $2)"
44   - FIRST=false
  41 + if [[ ${NO} -eq ${UNITS} ]]; then
  42 + printf "└─ %s %13.13s\n" \
  43 + "$(timestring "$1" "$2")" \
  44 + "$(formattime $2)"
  45 + else
  46 + printf "├─ %s %13.13s\n" \
  47 + "$(timestring "$1" "$2")" \
  48 + "$(formattime $2)"
  49 + fi
  50 + NO=$((NO+1))
45 51 done
46 52 done
47 53 }
48 54
  55 +function timestring() {
  56 + local END="$1"
  57 + local DUR="$2"
  58 + local FORMAT="%d.%m.%Y %H:%M:%S"
  59 +
  60 + eval set -- ${DUR//:/ }
  61 +
  62 + local START=$(date -u -d \
  63 + "${END}-${1}days-${2}hours-${3}minutes-${4}seconds" \
  64 + +%Y-%m-%dT%H:%M:%SZ)
  65 + printf "%s - %s" \
  66 + "$(date -d "${START}" +${FORMAT})" \
  67 + "$(date -d "${END}" +${FORMAT})"
  68 +}
  69 +
49 70 function timesheet() {
50 71 local PHRASE="1-week-ago"
51 72 local START="$(date +%Y-%m-%d -d ${PHRASE})"
... ... @@ -55,10 +76,15 @@ function timesheet() {
55 76 local BLOCKED="$(showall $(uuids +BLOCKED $@))"
56 77 local BLOCKING="$(showall $(uuids +BLOCKING $@))"
57 78
58   - DONE="${DONE:+${DONE}${NL}}"
59   - UPCOMING="${UPCOMING:+${UPCOMING}${NL}}"
60   - BLOCKED="${BLOCKED:+${BLOCKED}${NL}}"
61   - BLOCKING="${BLOCKING:+${BLOCKING}${NL}}"
  79 + DONE="${DONE:-No tasks}"
  80 + UPCOMING="${UPCOMING:-No tasks}"
  81 + BLOCKED="${BLOCKED:-No tasks}"
  82 + BLOCKING="${BLOCKING:-No tasks}"
  83 +
  84 + DONE="${DONE}${NL}"
  85 + UPCOMING="${UPCOMING}${NL}"
  86 + BLOCKED="${BLOCKED}${NL}"
  87 + BLOCKING="${BLOCKING}${NL}"
62 88
63 89 printf " (generated at %s)\n\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n" \
64 90 "${TODAY}" \
... ... @@ -74,9 +100,9 @@ function timesheet() {
74 100 halfyear="entry.after:$(date -d '6 month ago' +%F)"
75 101 twoyears="entry.after:$(date -d '2 years ago' +%F)"
76 102
77   - printf "%s%s\n\n%s%s\n%s\n\n%s\n\n%s\n" \
  103 + printf "%s\n%s\n\n%s%s\n%s\n\n%s\n\n%s\n" \
78 104 "$(bold "" "Summary")" \
79   - "$(task rc._forcecolor=on $@ summary 2>/dev/null)" \
  105 + "$(task rc._forcecolor=on $@ summary 2>/dev/null|sed '/./,$!d')" \
80 106 "$(bold "" "History")" \
81 107 "$(task rc._forcecolor=on $@ ${halfyear} history 2>/dev/null)" \
82 108 "$(task rc._forcecolor=on $@ ${halfyear} ghistory 2>/dev/null)" \
... ...
Please register or login to post a comment