From 3e85006a6c65a4f4adc3eac3d70cfc825f24bcbe Mon Sep 17 00:00:00 2001 From: Gardouille Date: Mon, 11 Oct 2021 15:18:28 +0200 Subject: [PATCH] Taskwarrior: new function to mark a task as done --- zshrc | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/zshrc b/zshrc index 60bc5ab..25602d0 100644 --- a/zshrc +++ b/zshrc @@ -458,6 +458,48 @@ function tadel() { unset tadel_confirmation tadel_task_id } ## }}} +## Mark a task as done {{{ +function tadone() { + # Verify argument + if [ "${#}" -eq 0 ]; then + ## If no argument + ## Ask the user to choose a task description from the last week Timewarrior activities {{{ + timew summary :week :ids || return 0 + + printf '%b' "Enter the ${MAGENTAB}a pattern${RESET} matching the expected task to mark as complete : " + read -r tadone_task_regexp + else + ## Merge all args into one var + tadone_task_regexp="${*}" + ## }}} + fi + + #printf '%b' "Pattern to search a task is ${REDB}${tadone_task_regexp}${RESET}.\n" + local tadone_task_id=$(task "${tadone_task_regexp}" simpleid | grep --after-context=2 -- ID | tail --lines=1 || return 0) + + # If no task with this ID exists, exit function {{{ + if [ -z "${tadone_task_id}" ]; then + printf '%b' "No available task with ${REDB}${tadone_task_regexp}${RESET} pattern." + return 1 + fi + # }}} + + # Get task's description + local tadone_task_desc=$(task "${tadone_task_id}" | sed -n "s/^Description *\(.*\)/\1/p") + + printf '%b' "Mark the task \"${MAGENTAB}${tadone_task_id} − ${tadone_task_desc}${RESET}\" as done [Y/n] ? " + read -r tadone_confirmation + + # Check confirmation + if printf -- '%s' "${tadone_confirmation:=y}" | grep --quiet --word-regexp -- "y"; then + task "${tadone_task_id}" done + printf '%b' "\"${MAGENTAB}${tadone_task_id} − ${tadone_task_desc}${RESET}\" task is now complete." + fi + + # Unset defined variables + unset tadone_confirmation tadone_task_regexp +} +## }}} ## Completion {{{ zstyle ':completion:*:*:task:*' verbose yes