New taskw func to take notes

This commit is contained in:
gardouille 2021-11-26 15:57:01 +01:00
parent e3808835e6
commit e60ee19740
Signed by: gardouille
GPG Key ID: E759BAA22501AF32
1 changed files with 78 additions and 38 deletions

116
zshrc
View File

@ -465,44 +465,6 @@ function tadel() {
}
## }}}
## Mark a task as done {{{
function tapurge() {
# Verify argument
if [ "${#}" -eq 0 ]; then
## If no argument
## Ask the user to choose a task description from the deleted tasks list {{{
task all status:deleted || return 0
printf '%b' "Enter few ${MAGENTAB}words matching the description${RESET} of the expected task to purge : "
read -r tapurge_task_regexp
else
## Merge all args into one var
tapurge_task_regexp="${*}"
## }}}
fi
local 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 [ -z "${tapurge_task_desc}" ]; then
printf '%b' "No available task with ${REDB}${tapurge_task_regexp}${RESET} pattern."
return 1
fi
# }}}
printf '%b' "Completly purge the task \"${MAGENTAB}${tapurge_task_desc}${RESET}\" [Y/n] ? "
read -r tapurge_confirmation
# Check confirmation
if printf -- '%s' "${tapurge_confirmation:=y}" | grep --quiet --word-regexp -- "y"; then
task rc.confirmation:no "${tapurge_task_desc}" purge
printf '%b' "\"${MAGENTAB}${tapurge_task_desc}${RESET}\" was purged."
fi
# Unset defined variables
unset tapurge_confirmation tapurge_task_regexp
}
## }}}
## Mark a task as done {{{
function tadone() {
# Verify argument
if [ "${#}" -eq 0 ]; then
@ -544,6 +506,84 @@ function tadone() {
unset tadone_confirmation tadone_task_regexp
}
## }}}
## Purge an old task {{{
function tapurge() {
# Verify argument
if [ "${#}" -eq 0 ]; then
## If no argument
## Ask the user to choose a task description from the deleted tasks list {{{
task all status:deleted || return 0
printf '%b' "Enter few ${MAGENTAB}words matching the description${RESET} of the expected task to purge : "
read -r tapurge_task_regexp
else
## Merge all args into one var
tapurge_task_regexp="${*}"
## }}}
fi
local 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 [ -z "${tapurge_task_desc}" ]; then
printf '%b' "No available task with ${REDB}${tapurge_task_regexp}${RESET} pattern."
return 1
fi
# }}}
printf '%b' "Completly purge the task \"${MAGENTAB}${tapurge_task_desc}${RESET}\" [Y/n] ? "
read -r tapurge_confirmation
# Check confirmation
if printf -- '%s' "${tapurge_confirmation:=y}" | grep --quiet --word-regexp -- "y"; then
task rc.confirmation:no "${tapurge_task_desc}" purge
printf '%b' "\"${MAGENTAB}${tapurge_task_desc}${RESET}\" was purged."
fi
# Unset defined variables
unset tapurge_confirmation tapurge_task_regexp
}
## }}}
## Take note for a task {{{
function tanote() {
# Verify argument
if [ "${#}" -eq 0 ]; then
## If no argument
## Ask the user to choose a task description from the recent tasks {{{
task simple limit:page || return 0
printf '%b' "Enter ${MAGENTAB}a pattern${RESET} matching the expected task that need notes : "
read -r tanote_task_regexp
else
## Merge all args into one var
tanote_task_regexp="${*}"
## }}}
fi
local 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 [ -z "${tanote_task_id}" ]; then
printf '%b' "No available task with ${REDB}${tanote_task_regexp}${RESET} pattern."
return 1
fi
# }}}
# Get task's description
local 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] ? "
read -r tanote_confirmation
# Check confirmation
if printf -- '%s' "${tanote_confirmation:=y}" | grep --quiet --word-regexp -- "y"; then
task note "${tanote_task_id}"
fi
# Unset defined variables
unset tanote_confirmation tanote_task_regexp
}
## }}}
## Completion {{{
zstyle ':completion:*:*:task:*' verbose yes