From d0370b62c0e3990903f3a84663b970bfdf812e56 Mon Sep 17 00:00:00 2001 From: Gardouille Date: Mon, 11 Oct 2021 09:16:08 +0200 Subject: [PATCH] Taskwarrior: function to delete a task --- zshrc | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/zshrc b/zshrc index 921fd5b..60bc5ab 100644 --- a/zshrc +++ b/zshrc @@ -419,6 +419,45 @@ function tasec() { task $search all || return 0 } ## }}} +## Delete a task {{{ +function tadel() { + # Verify argument + if [ "${#}" -eq 1 ]; then + ## Get the first arg as task ID + tadel_task_id="${1}" + else + ## If no argument or more than one + ## Ask the user to choose an ID in the 20 more recents tasks {{{ + task newest limit:20 || return 0 + + printf '%b' "Enter the ${MAGENTAB}ID${RESET} of the task to remove : " + read -r tadel_task_id + ## }}} + fi + + # If no task with this ID exists, exit function {{{ + if ! task "${tadel_task_id}" | grep --quiet -- "^ID *${tadel_task_id}"; then + printf '%b' "No available task with ${REDB}${tadel_task_id}${RESET} ID." + return 1 + fi + # }}} + + # Get task's description + local tadel_task_desc=$(task "${tadel_task_id}" | sed -n "s/^Description *\(.*\)/\1/p") + + printf '%b' "Delete the task \"${MAGENTAB}${tadel_task_id} − ${tadel_task_desc}${RESET}\" [Y/n] ? " + read -r tadel_confirmation + + # Check confirmation + if printf -- '%s' "${tadel_confirmation:=y}" | grep --quiet --word-regexp -- "y"; then + task "${tadel_task_id}" delete + printf '%b' "\"${MAGENTAB}${tadel_task_id} − ${tadel_task_desc}${RESET}\" task was removed." + fi + + # Unset defined variables + unset tadel_confirmation tadel_task_id +} +## }}} ## Completion {{{ zstyle ':completion:*:*:task:*' verbose yes @@ -428,6 +467,7 @@ zstyle ':completion:*:*:task:*' group-name '' # }}} # Timewarrior {{{ ## Aliases +alias tid="tiday" alias timv="timove" ## Functions