Timewarrior function to delete a time tracking

This commit is contained in:
gardouille 2021-10-07 17:47:15 +02:00
parent a865ebdd7b
commit 344e18b126
Signed by: gardouille
GPG Key ID: E759BAA22501AF32
1 changed files with 36 additions and 0 deletions

36
zshrc
View File

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