Timew: Add default day for timove function

This commit is contained in:
gardouille 2021-10-29 12:12:31 +02:00
parent 925f6816fd
commit e3808835e6
Signed by: gardouille
GPG Key ID: E759BAA22501AF32
1 changed files with 26 additions and 15 deletions

41
zshrc
View File

@ -854,59 +854,70 @@ function tiend() {
function timove() {
# Define new_start empty by default
timove_task_new_start=""
timove_time_new_start=""
# Verify argument
case "${#}" in
1 )
## Get the first arg as task ID
timove_task_id="${1}"
timove_time_id="${1}"
;;
2 )
## Get the first arg as task ID
timove_task_id="${1}"
timove_time_id="${1}"
## Get the second arg as new start time for the task
timove_task_new_start="${2}"
timove_time_new_start="${2}"
;;
* )
## Ask the user to choose an ID in tasks from the yesterday {{{
timew summary from yesterday :ids || return 0
printf '%b' "Enter the ${MAGENTAB}ID${RESET} of the task to move : "
read -r timove_task_id
read -r timove_time_id
## }}}
;;
esac
# If no task with this ID exists in the last month, exit function {{{
if ! timew summary :month :ids | grep --quiet -- " @${timove_task_id} "; then
printf '%b' "No available task in the last month with ${REDB}${timove_task_id}${RESET} ID."
if ! timew summary :month :ids | grep --quiet -- " @${timove_time_id} "; then
printf '%b' "No available task in the last month with ${REDB}${timove_time_id}${RESET} ID."
return 1
fi
# }}}
# Get task's description from all task of this month
local timove_task_desc=$(timew summary :month :ids | sed -n "s/.*@\(${timove_task_id} .*\)/\1/p" | sed 's/ */ /g')
local timove_time_desc=$(timew summary :month :ids | sed -n "s/.*@\(${timove_time_id} .*\)/\1/p" | sed 's/ */ /g')
# Get time tracking's start day from all time tracking
local timove_time_start_day=$(timew export | sed -nE "s/^\{\"id\":${timove_time_id},\"start\":\"([0-9]{4})([0-9]{2})([0-9]{2})T.*end.*/\1-\2-\3/p")
# Check or ask for new start time {{{
if [ -z "${timove_task_new_start}" ]; then
printf '%b' "Enter the ${MAGENTAB}new start time${RESET} (or new date 'YYYY-MM-DD${REDB}T${RESET}HH:MM:SS') for this task : "
read -r timove_task_new_start
if [ -z "${timove_time_new_start}" ]; then
printf '%b' "Enter the ${MAGENTAB}new start time${RESET} (or new date 'YYYY-MM-DD${REDB}T${RESET}HH:MM:SS'; default day is ${timove_time_start_day}) for this task : "
read -r timove_time_new_start
fi
# }}}
printf '%b' "Move \"${MAGENTAB}${timove_task_desc}${RESET}\" to ${REDB}=> ${timove_task_new_start} <=${RESET} [Y/n] ? "
printf '%b' "Move \"${MAGENTAB}${timove_time_desc}${RESET}\" to ${REDB}=> ${timove_time_new_start} <=${RESET} [Y/n] ? "
read -r timove_confirmation
# Check confirmation
if printf -- '%s' "${timove_confirmation:=y}" | grep --quiet --word-regexp -- "y"; then
timew move @"${timove_task_id}" "${timove_task_new_start}" || return 0
printf '%b' "${timove_task_desc} was moved to ${timove_task_new_start}."
## If the new start time entered by user contains a "T" (user enter a dateTtime)
if printf -- '%s' "${timove_time_new_start}" | grep --quiet -- "T"; then
timew move @"${timove_time_id}" "${timove_time_new_start}" || return 0
printf '%b' "${timove_time_desc} was moved to ${timove_time_new_start}."
else
timew move @"${timove_time_id}" "${timove_time_start_day}T${timove_time_new_start}" || return 0
printf '%b' "start time of ${timove_time_desc} is now ${timove_time_start_day}T${timove_time_new_start}."
fi
fi
# Unset defined variables
unset timove_confirmation timove_task_id timove_task_new_start
unset timove_confirmation timove_time_id timove_time_new_start
}
## }}}