From a865ebdd7bbe5392fc97a523d0fd66c8d91a8818 Mon Sep 17 00:00:00 2001 From: Gardouille Date: Thu, 7 Oct 2021 16:53:17 +0200 Subject: [PATCH] Timewarrior function to double spent time on a task --- zshenv | 1 + zshrc | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/zshenv b/zshenv index a638077..5041d78 100644 --- a/zshenv +++ b/zshenv @@ -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' diff --git a/zshrc b/zshrc index 638b3bb..751c242 100644 --- a/zshrc +++ b/zshrc @@ -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 +} +## }}} # }}}