Taskwarrior: new function to mark a task as done

This commit is contained in:
Jeremy Gardais 2021-10-11 15:18:28 +02:00
parent d0370b62c0
commit 3e85006a6c
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 42 additions and 0 deletions

42
zshrc
View File

@ -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