diff --git a/zshrc b/zshrc index e01d87a..921fd5b 100644 --- a/zshrc +++ b/zshrc @@ -400,11 +400,11 @@ function load-gpg-agent() { # Taskwarrior {{{ ## Aliases alias t="task" - -## By tag +### Filter by tag alias tawork="task +work | head" alias taperso="task +perso | head" +## Functions ## search a task by it's name (case INsensitive) {{{ function tase() { local search="" @@ -420,12 +420,17 @@ function tasec() { } ## }}} -## Completion +## Completion {{{ zstyle ':completion:*:*:task:*' verbose yes zstyle ':completion:*:*:task:*:descriptions' format '%U%B%d%b%u' zstyle ':completion:*:*:task:*' group-name '' +## }}} # }}} # Timewarrior {{{ +## Aliases +alias timv="timove" + +## Functions ## Display tasks of today {{{ function tiday() { if [ "${#}" -eq 0 ]; then @@ -581,6 +586,65 @@ function tirm() { unset tirm_confirmation tirm_task_id } ## }}} +## Move a time tracking {{{ +function timove() { + + # Define new_start empty by default + timove_task_new_start="" + + # Verify argument + case "${#}" in + 1 ) + ## Get the first arg as task ID + timove_task_id="${1}" + ;; + 2 ) + ## Get the first arg as task ID + timove_task_id="${1}" + + ## Get the second arg as new start time for the task + timove_task_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 + ## }}} + ;; + 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." + 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') + + # 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 + fi + # }}} + + printf '%b' "Move \"${MAGENTAB}${timove_task_desc}${RESET}\" to ${REDB}=> ${timove_task_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}." + fi + + # Unset defined variables + unset timove_confirmation timove_task_id timove_task_new_start +} +## }}} # }}}