Commit 7b10c057cb8f4a355ff9b47283eb4a2713ddd114

Authored by Georg Hopp
1 parent 1011f336

Options and Arguments for report

Showing 1 changed file with 68 additions and 17 deletions
@@ -6,35 +6,44 @@ source $0:A:h/ttyhelper.sh @@ -6,35 +6,44 @@ source $0:A:h/ttyhelper.sh
6 6
7 function tasksallsince() { 7 function tasksallsince() {
8 [[ $# -lt 1 ]] && return 1 8 [[ $# -lt 1 ]] && return 1
9 - local DATE=$1  
10 - shift  
11 - taskuuids \( \( \( +COMPLETED or +DELETED \) end.after:$DATE \) or \  
12 - +PENDING \) $@ 9 + taskuuids \(\(\( +COMPLETED or +DELETED \) end.after:${1} \) \
  10 + or +PENDING \) $@
13 } 11 }
14 12
15 function datetimedescription() { 13 function datetimedescription() {
16 - for UUID in $(tasksallsince 2018-03-31) 14 + [[ $# -lt 1 ]] && return 1
  15 + for UUID in $(tasksallsince $@)
17 do 16 do
18 DESCRIPTION="$(taskdescription $UUID)" 17 DESCRIPTION="$(taskdescription $UUID)"
19 PROJECT="$(taskproject $UUID)" 18 PROJECT="$(taskproject $UUID)"
  19 + COMPLETED="$(taskuuids $UUID \( +COMPLETED or +DELETED \))"
20 for T in $(tasktimes $UUID) 20 for T in $(tasktimes $UUID)
21 do 21 do
22 extracttime $T 22 extracttime $T
23 - printf "%s;%s;%s;%s\n" $TIMEKEY $TIME $PROJECT $DESCRIPTION 23 + printf "%s;%s;%s;%s;%s\n" \
  24 + $TIMEKEY $TIME $PROJECT $DESCRIPTION $COMPLETED
24 done 25 done
25 done 26 done
26 } 27 }
27 28
28 function report() { 29 function report() {
29 - for LINE in "${(f)$(datetimedescription|sort -t\; -k1)}" 30 + [[ $# -lt 1 ]] && return 1
  31 + local D DATE T
  32 + DATE=$1
  33 + for LINE in "${(f)$(datetimedescription $@|sort -t\; -f -k1,1 -k3,3)}"
30 do 34 do
31 set -- ${(s(;))LINE} 35 set -- ${(s(;))LINE}
32 - if [[ $DATE != $1 ]]  
33 - then  
34 - DATE=$1  
35 - printf "%s\n" $(underline "" $DATE)  
36 - fi  
37 - printf "%s [%s] - %s\n" $(bold "" $2) $3 $4 36 + if [[ -n $1 && $(date -d $1 +%s) -ge $(date -d $DATE +%s) ]]
  37 + then
  38 + if [[ $D != $1 ]]
  39 + then
  40 + D=$1
  41 + printf "%s\n" $(underline "" $D)
  42 + fi
  43 + T=$2
  44 + if [[ -n $5 ]] && T=$(bold "" $T)
  45 + if [[ -n $D ]] && printf "%s [%s] - %s\n" $T $3 $4
  46 + fi
38 done 47 done
39 } 48 }
40 49
@@ -43,16 +52,58 @@ function usage() { @@ -43,16 +52,58 @@ function usage() {
43 Usage: %s [-?] [DATETIME] [FILTER] 52 Usage: %s [-?] [DATETIME] [FILTER]
44 53
45 OPTIONS: 54 OPTIONS:
46 - -?, --help Show this help  
47 - 55 + -?, --help Show this help
  56 + -d, --date DATETIME is a date and time identifier as accepted by the
  57 + date command. It specifies how long back done tasks
  58 + should be considered.
  59 +
48 FILTER can be additional taskwarriors filters to limit the result 60 FILTER can be additional taskwarriors filters to limit the result
49 any further. 61 any further.
50 - DATETIME is a date and time identifier as accepted by the date command.  
51 - It specifies how long back done tasks should be considered.  
52 USAGE 62 USAGE
53 ) 63 )
54 /usr/bin/printf "${USAGE}\n" $0 64 /usr/bin/printf "${USAGE}\n" $0
55 } 65 }
56 66
  67 +#
  68 +# parse command line arguments
  69 +#
  70 +SHORTOPTS=?d:
  71 +LONGOPTS=help,date
  72 +ARGS=$(getopt -o ${SHORTOPTS} --long ${LONGOPTS} -n report -- $@)
  73 +if [ $? -ne 0 ]
  74 +then
  75 + usage $0
  76 + exit 1
  77 +fi
  78 +eval set -- ${=ARGS}
  79 +unset ARGS
  80 +
  81 +while true
  82 +do
  83 + case $1 in
  84 + '-?'|'--help')
  85 + shift
  86 + usage $0
  87 + exit 0
  88 + ;;
  89 + '-d'|'--date')
  90 + DATEFROM=$(date -d ${2} +%Y-%m-%d)
  91 + shift 2
  92 + continue
  93 + ;;
  94 + '--')
  95 + shift
  96 + break
  97 + ;;
  98 + *)
  99 + echo 'Internal error!' >&2
  100 + exit 1
  101 + ;;
  102 + esac
  103 +done
  104 +
  105 +DATEFROM=${DATEFROM:-$(date +%Y-%m-01)}
  106 +report $DATEFROM $@
  107 +#datetimedescription $DATEFROM $@|sort -t\; -f -k1,1 -k3,3
57 108
58 # vim: set et ts=4 sw=4: 109 # vim: set et ts=4 sw=4:
Please register or login to post a comment