Taskwarrior: function to delete a task

This commit is contained in:
gardouille 2021-10-11 09:16:08 +02:00
parent 9ddd370b4a
commit d0370b62c0
Signed by: gardouille
GPG Key ID: E759BAA22501AF32
1 changed files with 40 additions and 0 deletions

40
zshrc
View File

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