Timew: Add default day for timove function
This commit is contained in:
parent
925f6816fd
commit
e3808835e6
41
zshrc
41
zshrc
|
@ -854,59 +854,70 @@ function tiend() {
|
||||||
function timove() {
|
function timove() {
|
||||||
|
|
||||||
# Define new_start empty by default
|
# Define new_start empty by default
|
||||||
timove_task_new_start=""
|
timove_time_new_start=""
|
||||||
|
|
||||||
# Verify argument
|
# Verify argument
|
||||||
case "${#}" in
|
case "${#}" in
|
||||||
1 )
|
1 )
|
||||||
## Get the first arg as task ID
|
## Get the first arg as task ID
|
||||||
timove_task_id="${1}"
|
timove_time_id="${1}"
|
||||||
;;
|
;;
|
||||||
2 )
|
2 )
|
||||||
## Get the first arg as task ID
|
## 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
|
## 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 {{{
|
## Ask the user to choose an ID in tasks from the yesterday {{{
|
||||||
timew summary from yesterday :ids || return 0
|
timew summary from yesterday :ids || return 0
|
||||||
|
|
||||||
printf '%b' "Enter the ${MAGENTAB}ID${RESET} of the task to move : "
|
printf '%b' "Enter the ${MAGENTAB}ID${RESET} of the task to move : "
|
||||||
read -r timove_task_id
|
read -r timove_time_id
|
||||||
## }}}
|
## }}}
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# If no task with this ID exists in the last month, exit function {{{
|
# If no task with this ID exists in the last month, exit function {{{
|
||||||
if ! timew summary :month :ids | grep --quiet -- " @${timove_task_id} "; then
|
if ! timew summary :month :ids | grep --quiet -- " @${timove_time_id} "; then
|
||||||
printf '%b' "No available task in the last month with ${REDB}${timove_task_id}${RESET} ID."
|
printf '%b' "No available task in the last month with ${REDB}${timove_time_id}${RESET} ID."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# Get task's description from all task of this month
|
# 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 {{{
|
# Check or ask for new start time {{{
|
||||||
if [ -z "${timove_task_new_start}" ]; then
|
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') for this task : "
|
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_task_new_start
|
read -r timove_time_new_start
|
||||||
fi
|
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
|
read -r timove_confirmation
|
||||||
|
|
||||||
# Check confirmation
|
# Check confirmation
|
||||||
if printf -- '%s' "${timove_confirmation:=y}" | grep --quiet --word-regexp -- "y"; then
|
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
|
fi
|
||||||
|
|
||||||
# Unset defined variables
|
# Unset defined variables
|
||||||
unset timove_confirmation timove_task_id timove_task_new_start
|
unset timove_confirmation timove_time_id timove_time_new_start
|
||||||
}
|
}
|
||||||
## }}}
|
## }}}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue