From cb7c5eafc0a747e1a9618d8f265d13f364f6a7eb Mon Sep 17 00:00:00 2001 From: Gardouille Date: Tue, 12 Oct 2021 13:48:06 +0200 Subject: [PATCH] Timew: New function to modify the end of a time --- zshrc | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/zshrc b/zshrc index d522a4f..3eb7314 100644 --- a/zshrc +++ b/zshrc @@ -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() {