{Task,Time}warrior only use local vars

This commit is contained in:
Jeremy Gardais 2023-02-21 14:46:51 +01:00
parent 8f9e91b3ff
commit 3721b4865c
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 62 additions and 50 deletions

112
zshrc
View File

@ -457,6 +457,10 @@ function tall() {
## }}} ## }}}
## Delete a task {{{ ## Delete a task {{{
function tadel() { function tadel() {
local tadel_task_id
local tadel_task_desc
local tadel_confirmation
# Verify argument # Verify argument
if [ "${#}" -eq 1 ]; then if [ "${#}" -eq 1 ]; then
## Get the first arg as task ID ## Get the first arg as task ID
@ -479,7 +483,7 @@ function tadel() {
# }}} # }}}
# Get task's description # Get task's description
local tadel_task_desc=$(task "${tadel_task_id}" | sed -n "s/^Description *\(.*\)/\1/p") tadel_task_desc=$(task "${tadel_task_id}" | sed -n "s/^Description *\(.*\)/\1/p")
printf '%b' "Delete the task \"${MAGENTAB}${tadel_task_id} ${tadel_task_desc}${RESET}\" [Y/n] ? " printf '%b' "Delete the task \"${MAGENTAB}${tadel_task_id} ${tadel_task_desc}${RESET}\" [Y/n] ? "
read -r tadel_confirmation read -r tadel_confirmation
@ -492,13 +496,15 @@ function tadel() {
# Also offer to purge this task # Also offer to purge this task
tapurge "${tadel_task_desc}" tapurge "${tadel_task_desc}"
# Unset defined variables
unset tadel_confirmation tadel_task_id
} }
## }}} ## }}}
## Mark a task as done {{{ ## Mark a task as done {{{
function tadone() { function tadone() {
local tadone_task_regexp
local tadone_task_id
local tadone_task_desc
local tadone_confirmation
# Verify argument # Verify argument
if [ "${#}" -eq 0 ]; then if [ "${#}" -eq 0 ]; then
## If no argument ## If no argument
@ -514,7 +520,7 @@ function tadone() {
fi fi
#printf '%b' "Pattern to search a task is ${REDB}${tadone_task_regexp}${RESET}.\n" #printf '%b' "Pattern to search a task is ${REDB}${tadone_task_regexp}${RESET}.\n"
local tadone_task_id=$(task "${tadone_task_regexp}" simpleid | grep --after-context=2 -- ID | tail --lines=1 || return 0) tadone_task_id=$(task "${tadone_task_regexp}" simpleid | grep --after-context=2 -- ID | tail --lines=1 || return 0)
# If no task with this ID exists, exit function {{{ # If no task with this ID exists, exit function {{{
if [ -z "${tadone_task_id}" ]; then if [ -z "${tadone_task_id}" ]; then
@ -524,7 +530,7 @@ function tadone() {
# }}} # }}}
# Get task's description # Get task's description
local tadone_task_desc=$(task "${tadone_task_id}" | sed -n "s/^Description *\(.*\)/\1/p") tadone_task_desc=$(task "${tadone_task_id}" | sed -n "s/^Description *\(.*\)/\1/p")
printf '%b' "Mark the task \"${MAGENTAB}${tadone_task_id} ${tadone_task_desc}${RESET}\" as done [Y/n] ? " printf '%b' "Mark the task \"${MAGENTAB}${tadone_task_id} ${tadone_task_desc}${RESET}\" as done [Y/n] ? "
read -r tadone_confirmation read -r tadone_confirmation
@ -534,13 +540,14 @@ function tadone() {
task "${tadone_task_id}" done task "${tadone_task_id}" done
printf '%b' "\"${MAGENTAB}${tadone_task_id} ${tadone_task_desc}${RESET}\" task is now complete." printf '%b' "\"${MAGENTAB}${tadone_task_id} ${tadone_task_desc}${RESET}\" task is now complete."
fi fi
# Unset defined variables
unset tadone_confirmation tadone_task_regexp
} }
## }}} ## }}}
## Purge an old task {{{ ## Purge an old task {{{
function tapurge() { function tapurge() {
local tapurge_task_regexp
local tapurge_task_desc
local tapurge_confirmation
# Verify argument # Verify argument
if [ "${#}" -eq 0 ]; then if [ "${#}" -eq 0 ]; then
## If no argument ## If no argument
@ -555,7 +562,7 @@ function tapurge() {
## }}} ## }}}
fi fi
local tapurge_task_desc=$(task "${tapurge_task_regexp}" simpledeleted | grep --after-context=2 -- "^Description" | tail --lines=1 || return 0) tapurge_task_desc=$(task "${tapurge_task_regexp}" simpledeleted | grep --after-context=2 -- "^Description" | tail --lines=1 || return 0)
# If no task with this Description exists, exit function {{{ # If no task with this Description exists, exit function {{{
if [ -z "${tapurge_task_desc}" ]; then if [ -z "${tapurge_task_desc}" ]; then
@ -572,13 +579,15 @@ function tapurge() {
task rc.confirmation:no "${tapurge_task_desc}" purge task rc.confirmation:no "${tapurge_task_desc}" purge
printf '%b' "\"${MAGENTAB}${tapurge_task_desc}${RESET}\" was purged." printf '%b' "\"${MAGENTAB}${tapurge_task_desc}${RESET}\" was purged."
fi fi
# Unset defined variables
unset tapurge_confirmation tapurge_task_regexp
} }
## }}} ## }}}
## Take note for a task {{{ ## Take note for a task {{{
function tanote() { function tanote() {
local tanote_task_regexp
local tanote_task_id
local tanote_task_desc
local tanote_confirmation
# Verify argument # Verify argument
if [ "${#}" -eq 0 ]; then if [ "${#}" -eq 0 ]; then
## If no argument ## If no argument
@ -593,7 +602,7 @@ function tanote() {
## }}} ## }}}
fi fi
local tanote_task_id=$(task "${tanote_task_regexp}" simpleid | grep --after-context=2 -- ID | tail --lines=1 || return 0) tanote_task_id=$(task "${tanote_task_regexp}" simpleid | grep --after-context=2 -- ID | tail --lines=1 || return 0)
# If no task with this ID exists, exit function {{{ # If no task with this ID exists, exit function {{{
if [ -z "${tanote_task_id}" ]; then if [ -z "${tanote_task_id}" ]; then
@ -603,7 +612,7 @@ function tanote() {
# }}} # }}}
# Get task's description # Get task's description
local tanote_task_desc=$(task "${tanote_task_id}" | sed -n "s/^Description *\(.*\)/\1/p") tanote_task_desc=$(task "${tanote_task_id}" | sed -n "s/^Description *\(.*\)/\1/p")
printf '%b' "Add notes to \"${MAGENTAB}${tanote_task_id} ${tanote_task_desc}${RESET}\" task [Y/n] ? " printf '%b' "Add notes to \"${MAGENTAB}${tanote_task_id} ${tanote_task_desc}${RESET}\" task [Y/n] ? "
read -r tanote_confirmation read -r tanote_confirmation
@ -612,9 +621,6 @@ function tanote() {
if printf -- '%s' "${tanote_confirmation:=y}" | grep --quiet --word-regexp -- "y"; then if printf -- '%s' "${tanote_confirmation:=y}" | grep --quiet --word-regexp -- "y"; then
task note "${tanote_task_id}" task note "${tanote_task_id}"
fi fi
# Unset defined variables
unset tanote_confirmation tanote_task_regexp
} }
## }}} ## }}}
@ -710,6 +716,9 @@ function tilastyear() {
function tidouble() { function tidouble() {
# Default duration time to add to a task # Default duration time to add to a task
local tidouble_extra_time="25mins" local tidouble_extra_time="25mins"
local tidouble_task_id
local tidouble_confirmation
local tidouble_task_desc
# Verify argument # Verify argument
if [ "${#}" -eq 1 ]; then if [ "${#}" -eq 1 ]; then
@ -733,7 +742,7 @@ function tidouble() {
# }}} # }}}
# Get task's description from all task of this year # Get task's description from all task of this year
local tidouble_task_desc=$(timew summary :year :ids | sed -n "s/.*@\(${tidouble_task_id} .*\)/\1/p" | sed 's/ */ /g') tidouble_task_desc=$(timew summary :year :ids | sed -n "s/.*@\(${tidouble_task_id} .*\)/\1/p" | sed 's/ */ /g')
printf '%b' "Add ${tidouble_extra_time} to \"${MAGENTAB}${tidouble_task_desc}${RESET}\" [Y/n] ? " printf '%b' "Add ${tidouble_extra_time} to \"${MAGENTAB}${tidouble_task_desc}${RESET}\" [Y/n] ? "
read -r tidouble_confirmation read -r tidouble_confirmation
@ -744,13 +753,14 @@ function tidouble() {
timew split @"${tidouble_task_id}" || return 0 timew split @"${tidouble_task_id}" || return 0
printf '%b' "${tidouble_extra_time} were added to \"${MAGENTAB}${tidouble_task_desc}${RESET}\" task." printf '%b' "${tidouble_extra_time} were added to \"${MAGENTAB}${tidouble_task_desc}${RESET}\" task."
fi fi
# Unset defined variables
unset tidouble_confirmation tidouble_task_id
} }
## }}} ## }}}
## Delete a time tracking {{{ ## Delete a time tracking {{{
function tirm() { function tirm() {
local tirm_task_id
local tirm_task_desc
local tirm_confirmation
# Verify argument # Verify argument
if [ "${#}" -eq 1 ]; then if [ "${#}" -eq 1 ]; then
## Get the first arg as task ID ## Get the first arg as task ID
@ -773,7 +783,7 @@ function tirm() {
# }}} # }}}
# Get task's description from all task of this year # Get task's description from all task of this year
local tirm_task_desc=$(timew summary :year :ids | sed -n "s/.*@\(${tirm_task_id} .*\)/\1/p" | sed 's/ */ /g') tirm_task_desc=$(timew summary :year :ids | sed -n "s/.*@\(${tirm_task_id} .*\)/\1/p" | sed 's/ */ /g')
printf '%b' "Delete to \"${MAGENTAB}${tirm_task_desc}${RESET}\" [Y/n] ? " printf '%b' "Delete to \"${MAGENTAB}${tirm_task_desc}${RESET}\" [Y/n] ? "
read -r tirm_confirmation read -r tirm_confirmation
@ -783,16 +793,17 @@ function tirm() {
timew delete @"${tirm_task_id}" || return 0 timew delete @"${tirm_task_id}" || return 0
printf '%b' "${tirm_task_desc} was deleted" printf '%b' "${tirm_task_desc} was deleted"
fi fi
# Unset defined variables
unset tirm_confirmation tirm_task_id
} }
## }}} ## }}}
## Modify the start of a time tracking {{{ ## Modify the start of a time tracking {{{
function tistart() { function tistart() {
# Define new_start empty by default # Define new_start empty by default
tistart_time_new_start="" local tistart_time_new_start=""
local tistart_time_id
local tistart_time_desc
local tistart_time_start_day
local tistart_confirmation
# Verify argument # Verify argument
case "${#}" in case "${#}" in
@ -825,10 +836,10 @@ function tistart() {
# }}} # }}}
# Get time tracking's description from all time tracking of this year # Get time tracking's description from all time tracking of this year
local tistart_time_desc=$(timew summary :year :ids | sed -n "s/.*@\(${tistart_time_id} .*\)/\1/p" | sed 's/ */ /g') tistart_time_desc=$(timew summary :year :ids | sed -n "s/.*@\(${tistart_time_id} .*\)/\1/p" | sed 's/ */ /g')
# Get time tracking's start day from all time tracking # Get time tracking's start day from all time tracking
local tistart_time_start_day=$(timew export | sed -nE "s/^\{\"id\":${tistart_time_id},\"start\":\"([0-9]{4})([0-9]{2})([0-9]{2})T.*end.*/\1-\2-\3/p") tistart_time_start_day=$(timew export | sed -nE "s/^\{\"id\":${tistart_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 "${tistart_time_new_start}" ]; then if [ -z "${tistart_time_new_start}" ]; then
@ -851,16 +862,18 @@ function tistart() {
timew modify start @"${tistart_time_id}" "${tistart_time_start_day}T${tistart_time_new_start}" || return 0 timew modify start @"${tistart_time_id}" "${tistart_time_start_day}T${tistart_time_new_start}" || return 0
fi fi
fi fi
# Unset defined variables
unset tistart_confirmation tistart_time_id tistart_time_new_start
} }
## }}} ## }}}
## Modify the end of a time tracking {{{ ## Modify the end of a time tracking {{{
function tiend() { function tiend() {
# Define new_end empty by default # Define new_end empty by default
tiend_time_new_end="" local tiend_time_new_end=""
local tiend_time_id
local tiend_time_new_end
local tiend_time_desc
local tiend_time_start_day
local tiend_confirmation
# Verify argument # Verify argument
case "${#}" in case "${#}" in
@ -893,10 +906,10 @@ function tiend() {
# }}} # }}}
# Get time tracking's description from all time tracking of this year # 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') tiend_time_desc=$(timew summary :year :ids | sed -n "s/.*@\(${tiend_time_id} .*\)/\1/p" | sed 's/ */ /g')
# Get time tracking's start day from all time tracking # Get time tracking's start day from all time tracking
local tiend_time_start_day=$(timew export | sed -nE "s/^\{\"id\":${tiend_time_id},\"start\":\"([0-9]{4})([0-9]{2})([0-9]{2})T.*end.*/\1-\2-\3/p") tiend_time_start_day=$(timew export | sed -nE "s/^\{\"id\":${tiend_time_id},\"start\":\"([0-9]{4})([0-9]{2})([0-9]{2})T.*end.*/\1-\2-\3/p")
# Check or ask for new end time {{{ # Check or ask for new end time {{{
if [ -z "${tiend_time_new_end}" ]; then if [ -z "${tiend_time_new_end}" ]; then
@ -919,16 +932,17 @@ function tiend() {
printf '%b' "End time of ${tiend_time_desc} is now ${tiend_time_start_day}T${tiend_time_new_end}." printf '%b' "End time of ${tiend_time_desc} is now ${tiend_time_start_day}T${tiend_time_new_end}."
fi fi
fi fi
# Unset defined variables
unset tiend_confirmation tiend_time_id tiend_time_new_end
} }
## }}} ## }}}
## Modify the duration of a time tracking {{{ ## Modify the duration of a time tracking {{{
function tiduration() { function tiduration() {
# Define new_duration empty by default # Define new_duration empty by default
tiduration_time_new_duration="" local tiduration_time_new_duration=""
local tiduration_time_id
local tiduration_time_new_duration
local tiduration_time_desc
local tiduration_confirmation
# Verify argument # Verify argument
case "${#}" in case "${#}" in
@ -961,7 +975,7 @@ function tiduration() {
# }}} # }}}
# Get time tracking's description from all time tracking of this year # 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') 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 {{{ # Check or ask for new end time {{{
if [ -z "${tiduration_time_new_duration}" ]; then if [ -z "${tiduration_time_new_duration}" ]; then
@ -978,16 +992,18 @@ function tiduration() {
timew resize @"${tiduration_time_id}" "${tiduration_time_new_duration}" || return 0 timew resize @"${tiduration_time_id}" "${tiduration_time_new_duration}" || return 0
printf '%b' "Duration of ${tiduration_time_desc} is now ${tiduration_time_new_duration}." printf '%b' "Duration of ${tiduration_time_desc} is now ${tiduration_time_new_duration}."
fi fi
# Unset defined variables
unset tiduration_confirmation tiduration_time_id tiduration_time_new_duration
} }
## }}} ## }}}
## Move a time tracking {{{ ## Move a time tracking {{{
function timove() { function timove() {
# Define new_start empty by default # Define new_start empty by default
timove_time_new_start="" local timove_time_new_start=""
local timove_time_id
local timove_time_new_start
local timove_time_desc
local timove_time_start_day
local timove_confirmation
# Verify argument # Verify argument
case "${#}" in case "${#}" in
@ -1020,10 +1036,10 @@ function timove() {
# }}} # }}}
# Get task's description from all task of this month # Get task's description from all task of this month
local timove_time_desc=$(timew summary :month :ids | sed -n "s/.*@\(${timove_time_id} .*\)/\1/p" | sed 's/ */ /g') 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 # 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") 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_time_new_start}" ]; then if [ -z "${timove_time_new_start}" ]; then
@ -1046,11 +1062,7 @@ function timove() {
timew move @"${timove_time_id}" "${timove_time_start_day}T${timove_time_new_start}" || return 0 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}." printf '%b' "start time of ${timove_time_desc} is now ${timove_time_start_day}T${timove_time_new_start}."
fi fi
fi fi
# Unset defined variables
unset timove_confirmation timove_time_id timove_time_new_start
} }
## }}} ## }}}