Timewarrior function to double spent time on a task

This commit is contained in:
gardouille 2021-10-07 16:53:17 +02:00
parent 64bb0a5482
commit a865ebdd7b
Signed by: gardouille
GPG Key ID: E759BAA22501AF32
2 changed files with 42 additions and 0 deletions

1
zshenv
View File

@ -11,6 +11,7 @@ export GREEN='\033[1;32m'
export YELLOW='\033[1;33m'
export BLUE='\033[34;40m'
export MAGENTA='\033[0;35m'
export MAGENTAB='\033[1;35m'
export CYAN='\033[36;40m'
export WHITE='\033[0;37m'
export WHITEB='\033[1;37m'

41
zshrc
View File

@ -498,6 +498,47 @@ function tilastyear() {
fi
}
## }}}
## Double spent time on a task {{{
## "double" cause by default my tasks runs for 25 minutes
function tidouble() {
# Default duration time to add to a task
tidouble_extra_time="25mins"
# Verify argument
if [ "${#}" -eq 1 ]; then
## Get the first arg as task ID
tidouble_task_id="${1}"
else
## If no argument or more than one
## Ask the user to choose an ID in tasks from the yesterday {{{
timew summary from yesterday :ids
printf '%b' "Enter the ${MAGENTAB}ID${RESET} of the task to double spent time should be doubled : "
read -r tidouble_task_id
## }}}
fi
# If no task with this ID exists, exit function {{{
if ! timew summary :year :ids | grep --quiet -- " @${tidouble_task_id} "; then
printf '%b' "No available task in the last year with ${REDB}${tidouble_task_id}${RESET} ID."
return 1
fi
# }}}
# Get task's description from all task of this year
tidouble_task_desc=$(timew summary :year :ids | sed -n "s/.*@\(${tidouble_task_id} .*\)/\1/p" | sed 's/ */ /g')
printf '%b' "Add ${tidouble_extra_time} to \"${MAGENTAB}${tidouble_task_desc}${RESET}\" [Y/n] ? "
read -r tidouble_confirmation
# Check confirmation
if printf -- '%s' "${tidouble_confirmation:=y}" | grep --quiet --word-regexp -- "y"; then
timew lengthen @"${tidouble_task_id}" "${tidouble_extra_time}" || return 0
timew split @"${tidouble_task_id}" || return 0
printf '%b' "${tidouble_extra_time} were added to \"${MAGENTAB}${tidouble_task_desc}${RESET}\" task."
fi
}
## }}}
# }}}