From e60ee197402a81d2ec0e61d97512d9a9713b68d2 Mon Sep 17 00:00:00 2001 From: Gardouille Date: Fri, 26 Nov 2021 15:57:01 +0100 Subject: [PATCH] New taskw func to take notes --- zshrc | 116 +++++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 78 insertions(+), 38 deletions(-) diff --git a/zshrc b/zshrc index 2c17811..535add0 100644 --- a/zshrc +++ b/zshrc @@ -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