report.sh 1.33 KB
#!/bin/zsh

source $0:A:h/datetimehelper.sh
source $0:A:h/taskhelper.sh
source $0:A:h/ttyhelper.sh

function tasksallsince() {
    [[ $# -lt 1 ]] && return 1
    local DATE=$1
    shift
    taskuuids \( \( \( +COMPLETED or +DELETED \) end.after:$DATE \) or \
        +PENDING \) $@
}

function datetimedescription() {
    for UUID in $(tasksallsince 2018-03-31)
    do
        DESCRIPTION="$(taskdescription $UUID)"
        PROJECT="$(taskproject $UUID)"
        for T in $(tasktimes $UUID)
        do
            extracttime $T
            printf "%s;%s;%s;%s\n" $TIMEKEY $TIME $PROJECT $DESCRIPTION
        done
    done
}

function report() {
    for LINE in "${(f)$(datetimedescription|sort -t\; -k1)}"
    do
        set -- ${(s(;))LINE}
        if [[ $DATE != $1 ]]
        then
            DATE=$1
            printf "%s\n" $(underline "" $DATE)
        fi
        printf "%s [%s] - %s\n" $(bold "" $2) $3 $4
    done
}

function usage() {
    local USAGE=$(cat <<-USAGE 
    Usage: %s [-?] [DATETIME] [FILTER] 
	
	OPTIONS: 
	  -?, --help    Show this help 
	
	FILTER can be additional taskwarriors filters to limit the result 
	any further. 
	DATETIME is a date and time identifier as accepted by the date command.
	It specifies how long back done tasks should be considered.
	USAGE
    )
    /usr/bin/printf "${USAGE}\n" $0
}


# vim: set et ts=4 sw=4: