Timew: New function to modify the end of a time

This commit is contained in:
gardouille 2021-10-12 13:48:06 +02:00
parent 349980f01b
commit cb7c5eafc0
Signed by: gardouille
GPG Key ID: E759BAA22501AF32
1 changed files with 59 additions and 0 deletions

59
zshrc
View File

@ -710,6 +710,65 @@ function tirm() {
unset tirm_confirmation tirm_task_id
}
## }}}
## Modify the end of a time tracking {{{
function tiend() {
# Define new_end empty by default
tiend_time_new_end=""
# Verify argument
case "${#}" in
1 )
## Get the first arg as time ID
tiend_time_id="${1}"
;;
2 )
## Get the first arg as time ID
tiend_time_id="${1}"
## Get the second arg as new end time for this track
tiend_time_new_end="${2}"
;;
* )
## Ask the user to choose an ID in time tracking from the yesterday {{{
timew summary from yesterday :ids || return 0
printf '%b' "Enter the ${MAGENTAB}ID${RESET} of the time tracking to modify : "
read -r tiend_time_id
## }}}
;;
esac
# If no time tracking exists with this ID, exit function {{{
if ! timew summary :year :ids | grep --quiet -- " @${tiend_time_id} "; then
printf '%b' "No available time tracking in the last year with ${REDB}${tiend_time_id}${RESET} ID."
return 1
fi
# }}}
# Get time tracking's description from all time tracking of this year
local tiend_time_desc=$(timew summary :year :ids | sed -n "s/.*@\(${tiend_time_id} .*\)/\1/p" | sed 's/ */ /g')
# Check or ask for new end time {{{
if [ -z "${tiend_time_new_end}" ]; then
printf '%b' "Enter the ${MAGENTAB}new end time${RESET} (or new date 'YYYY-MM-DD${REDB}T${RESET}HH:MM:SS') for this time tracking : "
read -r tiend_time_new_end
fi
# }}}
printf '%b' "Change end time of \"${MAGENTAB}${tiend_time_desc}${RESET}\" to ${REDB}=> ${tiend_time_new_end} <=${RESET} [Y/n] ? "
read -r tiend_confirmation
# Check confirmation
if printf -- '%s' "${tiend_confirmation:=y}" | grep --quiet --word-regexp -- "y"; then
timew modify end @"${tiend_time_id}" "${tiend_time_new_end}" || return 0
printf '%b' "End time of ${tiend_time_desc} is now ${tiend_time_new_end}."
fi
# Unset defined variables
unset tiend_confirmation tiend_time_id tiend_time_new_end
}
## }}}
## Move a time tracking {{{
function timove() {