Function to resize timewarrior record

This commit is contained in:
Jeremy Gardais 2023-02-04 09:30:34 +01:00
parent f05fb06e69
commit d3f75c0e11
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 60 additions and 0 deletions

60
zshrc
View File

@ -630,6 +630,7 @@ alias tid="tiday"
alias tiw="tiweek"
alias tim="timonth"
alias timv="timove"
alias tiresize="tiduration"
## Functions
## Display tasks of today {{{
@ -923,6 +924,65 @@ function tiend() {
unset tiend_confirmation tiend_time_id tiend_time_new_end
}
## }}}
## Modify the duration of a time tracking {{{
function tiduration() {
# Define new_duration empty by default
tiduration_time_new_duration=""
# Verify argument
case "${#}" in
1 )
## Get the first arg as time ID
tiduration_time_id="${1}"
;;
2 )
## Get the first arg as time ID
tiduration_time_id="${1}"
## Get the second arg as new end time for this track
tiduration_time_new_duration="${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 tiduration_time_id
## }}}
;;
esac
# If no time tracking exists with this ID, exit function {{{
if ! timew summary :year :ids | grep --quiet -- " @${tiduration_time_id} "; then
printf '%b' "No available time tracking in the last year with ${REDB}${tiduration_time_id}${RESET} ID."
return 1
fi
# }}}
# Get time tracking's description from all time tracking of this year
local tiduration_time_desc=$(timew summary :year :ids | sed -n "s/.*@\(${tiduration_time_id} .*\)/\1/p" | sed 's/ */ /g')
# Check or ask for new end time {{{
if [ -z "${tiduration_time_new_duration}" ]; then
printf '%b' "Enter the ${MAGENTAB}new duration${RESET} (eg. 25mins, 1hour…) for this time tracking : "
read -r tiduration_time_new_duration
fi
# }}}
printf '%b' "Change duration of \"${MAGENTAB}${tiduration_time_desc}${RESET}\" to ${REDB}=> ${tiduration_time_new_duration} <=${RESET} [Y/n] ? "
read -r tiduration_confirmation
# Check confirmation
if printf -- '%s' "${tiduration_confirmation:=y}" | grep --quiet --word-regexp -- "y"; then
timew resize @"${tiduration_time_id}" "${tiduration_time_new_duration}" || return 0
printf '%b' "Duration of ${tiduration_time_desc} is now ${tiduration_time_new_duration}."
fi
# Unset defined variables
unset tiduration_confirmation tiduration_time_id tiduration_time_new_duration
}
## }}}
## Move a time tracking {{{
function timove() {