zdconvert.sh (raw)
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 |
#!/bin/sh # format zeit data for easy transferrence to daptiv # Derek Stevens <nilix@nilfm.cc> # MIT License if [ "$1" = "--help" ]; then echo "usage:" echo " $0 WEEKS_AGO_START=1 WEEKS_AGO_END=1" echo " Print report of tracked time for the given weeks to stdout" exit 1 fi weeks_start=${1:-1} weeks_end=${2:-1} while [ ${weeks_start} -ge ${weeks_end} ]; do start=$(date -Is --date="0:00 Sat ${weeks_start} weeks ago") end=$(date -Is --date="23:59 Fri $((weeks_start - 1)) weeks ago") echo "week starting ${start}" zeit list --since ${start} --until ${end} --total --no-colors --decimal | tail -n2 i=${weeks_start} oldifs=${IFS} for d in Sat Sun Mon Tue Wed Thu Fri; do echo "${d}" [ "${d}" = $(date +"%a") ] && [ ${weeks_start} -eq 1 ] && i=$((i-1)) dayStart=$(date -Is --date="00:00 ${d} ${i} weeks ago") dayEnd=$(date -Is --date="23:59 ${d} ${i} weeks ago") IFS=" " for p in $(zeit list --since ${dayStart} --until ${dayEnd} --only-projects-and-tasks --no-colors | grep ◆ | awk '{for (i=2; i<NF; i++) printf $i " "; print $NF;}'); do echo "\t${p}:" ntasks=1 while read task; do echo "\t\t${task} $(zeit list --since ${dayStart} --until ${dayEnd} --project ${p} --decimal | awk '{print $(NF-1) "\n";}' | head -n${ntasks} | tail -n1)" ntasks=$((ntasks+1)) done << EOF $(zeit list --since ${dayStart} --until ${dayEnd} --project ${p} --decimal | awk '{for (i=2; i<NF; i++) printf $i " "; print $NF;}' | awk -F' on' '{print $1 "\n"}') EOF echo "\t\t$(zeit list --since ${dayStart} --until ${dayEnd} --project ${p} --total --decimal | tail -n2 | cut -f2- -d ' ')" done IFS=${oldifs} done weeks_start=$((weeks_start-1)) done |