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 +} +## }}} # }}}