From 344e18b12606a9951091a33d62a0ebff3a89197f Mon Sep 17 00:00:00 2001 From: Gardouille Date: Thu, 7 Oct 2021 17:47:15 +0200 Subject: [PATCH] Timewarrior function to delete a time tracking --- zshrc | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/zshrc b/zshrc index 751c242..3cd428d 100644 --- a/zshrc +++ b/zshrc @@ -539,6 +539,42 @@ function tidouble() { fi } ## }}} +## Delete a time tracking {{{ +function tirm() { + # Verify argument + if [ "${#}" -eq 1 ]; then + ## Get the first arg as task ID + tirm_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 delete : " + read -r tirm_task_id + ## }}} + fi + + # If no task with this ID exists, exit function {{{ + if ! timew summary :year :ids | grep --quiet -- " @${tirm_task_id} "; then + printf '%b' "No available task in the last year with ${REDB}${tirm_task_id}${RESET} ID." + return 1 + fi + # }}} + + # Get task's description from all task of this year + tirm_task_desc=$(timew summary :year :ids | sed -n "s/.*@\(${tirm_task_id} .*\)/\1/p" | sed 's/ */ − /g') + + printf '%b' "Delete to \"${MAGENTAB}${tirm_task_desc}${RESET}\" [Y/n] ? " + read -r tirm_confirmation + + # Check confirmation + if printf -- '%s' "${tirm_confirmation:=y}" | grep --quiet --word-regexp -- "y"; then + timew delete @"${tirm_task_id}" || return 0 + printf '%b' "${tirm_task_desc} was deleted" + fi +} +## }}} # }}}