diff --git a/t.sh b/t.sh index 63ed2f8..f5cdbb4 100755 --- a/t.sh +++ b/t.sh @@ -284,7 +284,7 @@ function loadtask() { dblog "open $1" file="$1" - res=$(cat "$file" | awk -F: 'BEGIN { checked=0; folded=0; } /^UID:/ { printf("uid©%s©",$2); } /^SUMMARY:/ { sub("SUMMARY:",""); printf("sum©%s©",$0); } /^CATEGORIES:/ { sub("^CATEGORIES:",""); printf("cats©%s©",$0); } /^DESCRIPTION:/ { sub("DESCRIPTION:",""); printf("desc©%s©",$0); } /^RELATED-TO/ { sub("^RELATED-TO.*:",""); printf("parent©%s©",$0); } /^X-OC-HIDESUBTASKS:1/ { folded=1; } /^STATUS:COMPLETED/ { checked=1; } END { printf("checked©%d©folded©%d\n",checked,folded); }') + res=$(cat "$file" | awk -F: 'BEGIN { checked=0; folded=0; } /^UID:/ { printf("uid©%s©",$2); } /^SUMMARY:/ { sub("SUMMARY:",""); printf("sum©%s©",$0); } /^CATEGORIES:/ { sub("^CATEGORIES:",""); printf("cats©%s©",$0); } /^DESCRIPTION:/ { sub("DESCRIPTION:",""); printf("desc©%s©",$0); } /^RELATED-TO/ { sub("^RELATED-TO.*:",""); printf("parent©%s©",$0); } /^X-OC-HIDESUBTASKS:1/ { folded=1; } /^STATUS:/ { stat=substr($0,8); if (stat == "COMPLETED") { checked=2; } else if (stat == "IN-PROCESS") { checked = 1 } } END { printf("checked©%d©folded©%d\n",checked,folded); }') IFS='©' read -ra tok <<< "$res" @@ -376,7 +376,8 @@ function marknotdone() { return 1 fi file="$dir/$uid.vcf" - sed -i '/^COMPLETED:/d;/^STATUS:COMPLETED/d;/PERCENT-COMPLETE:100/d' "$file" + #sed -i '/^COMPLETED:/d;/^STATUS:COMPLETED/d;/PERCENT-COMPLETE:100/d' "$file" + sed -i '/^COMPLETED:/d;/^STATUS:/d;/PERCENT-COMPLETE:/d' "$file" sedrv=$((sedrv + $?)) set_lastmodified $uid sedrv=$((sedrv + $?)) @@ -820,6 +821,52 @@ function unfold() { return $rv } + +function markinprogress() { + local uid sedrv rv file toadd1 str now + local children childuid ischild noun id + uid=$1 + id=$(getid $uid) + [[ $# -gt 1 ]] && ischild=1 || ischild=0 + [[ $ischild -eq 1 ]] && noun=subtask || noun=task + # already in progress? + if [[ ${taskchecked[$id]} -eq 1 ]]; then + error "$noun #${id} is already in progress" + return 1 + fi + str="END:VTODO" + now=$(date -u +'%Y%m%dT%H%M%SZ') + + file="$dir/$uid.vcf" + + # first remove any existing completion + sed -i '/^COMPLETED:/d;/^STATUS:COMPLETED/d;/PERCENT-COMPLETE:/d' "$file" + + # then add partial completion + toadd1="STATUS:IN-PROCESS" + sed -i "/$str/i $toadd1\n" "$file" + sedrv=$? + set_lastmodified $uid + sedrv=$((sedrv + $?)) + if [[ $sedrv -eq 0 ]]; then + action "Marked $noun #${id} as in-progress." + processed="$processed ${uid} " + loadtask "$file" + rv=0 + children=$(getchildren $uid) + for childuid in ${children}; do + markinprogress $childuid noprint + rv=$((rv + $?)) + done + else + failed="$failed ${uid} " + error "failed to mark $noun #${id} as in-progress" + rv=1 + fi + + return $rv +} + function markdone() { local uid sedrv rv file toadd1 toadd2 toadd3 str now local children childuid ischild noun id @@ -828,7 +875,7 @@ function markdone() { [[ $# -gt 1 ]] && ischild=1 || ischild=0 [[ $ischild -eq 1 ]] && noun=subtask || noun=task # already complete? - if [[ ${taskchecked[$id]} -eq 1 ]]; then + if [[ ${taskchecked[$id]} -eq 2 ]]; then error "$noun #${id} is already completed" return 1 fi @@ -968,10 +1015,11 @@ function showit() { local children nchildren charcol local notecol bcol bl br space pre end local showkids - local reset catstr catcol + local reset catstr catcol lrogcol reset="$PLAIN" catcol="\033[38;2;255;165;0m" + progcol="\033[38;2;212;0;255m" showkids=1 if [[ $1 == "--nochildren" ]]; then @@ -1001,12 +1049,19 @@ function showit() { col="$reset" notecol="$YELLOW" - if [[ ${taskchecked[$id]} -eq 1 ]]; then + end="" + if [[ ${taskchecked[$id]} -eq 2 ]]; then char="✓" + charcol="$GREEN" col="$col$STRIKE" notecol="$notecol$STRIKE" + elif [[ ${taskchecked[$id]} -eq 1 ]]; then + char="&" + charcol="$progcol" + end="${progcol}...${reset}" else char=" " + charcol="$GREEN" fi if [[ $uid == $hilite ]]; then @@ -1014,7 +1069,6 @@ function showit() { notecol="$notecol$HILITE" fi - charcol="$GREEN" if [[ $nchildren -gt 0 && ${taskfolded[$id]} -eq 1 ]]; then bcol=$brackfold bl="(" @@ -1022,7 +1076,7 @@ function showit() { #col="$col$FOLDBG" space=" " pre="" - end=" $reset$CYAN${BOLD}[$nchildren subtasks]" + end=" $end$reset$CYAN${BOLD}[$nchildren subtasks]" if [[ $char == " " ]]; then char="+" charcol="$BOLD$CYAN" @@ -1033,7 +1087,6 @@ function showit() { br="]" space=" " pre="" - end="" fi if [[ -z ${taskcats[$id]} ]]; then @@ -1428,6 +1481,7 @@ addcmd "unfold" "unfold " "Unfold a parent task (show its children)" "unfold addcmd "toggle" "toggle " "Fold/Unfold a parent task" "toggle|z|zz" SUPPORTS_ALL addcmd "done" "done " "Complete a task" "done|x|complete" SUPPORTS_ALL addcmd "notdone" "notdone " "Uncomplete a task" "notdone|o|incomplete|uncomplete|clear" SUPPORTS_ALL +addcmd "inprogress" "inprogress " "Mark a task as in progress" "inprogress|progress|inp|prog|i|p" SUPPORTS_ALL addcmd "add" "add [parent] " "Add a new task [as subtask of parent]" "a|add|new|create" addcmd "del" "del [id1] .. [idX]" "Delete given task(s)" "del|rm|delete" addcmd "cleanup" "cleanup" "Delete all completed tasks" "cleanup|clean|flush|dc" @@ -1647,7 +1701,7 @@ elif [[ $mode == "cleanup" ]]; then action "Deleting all completed tasks." for id in ${!taskuid[@]}; do uid=$(getuid $id) - [[ ${taskchecked[$id]} -eq 1 ]] && delq_add $uid + [[ ${taskchecked[$id]} -eq 2 ]] && delq_add $uid done delq_process @@ -1688,9 +1742,11 @@ else elif [[ $mode == "unfold" && ${taskfolded[$id]} -eq 1 ]]; then match=1 kids="--nochildren" - elif [[ $mode == "done" && ${taskchecked[$id]} -eq 0 ]]; then + elif [[ $mode == "done" && ${taskchecked[$id]} -ne 2 ]]; then match=1 - elif [[ $mode == "notdone" && ${taskchecked[$id]} -eq 1 ]]; then + elif [[ $mode == "notdone" && ${taskchecked[$id]} -ne 0 ]]; then + match=1 + elif [[ $mode == "inprogress" && ${taskchecked[$id]} -ne 1 ]]; then match=1 elif [[ $mode == "list" && $hasparent -eq 0 ]]; then match=1 @@ -1767,6 +1823,8 @@ else markdone $uid elif [[ $mode == "notdone" ]]; then marknotdone $uid + elif [[ $mode == "inprogress" ]]; then + markinprogress $uid elif [[ $mode == "fold" ]]; then fold $uid elif [[ $mode == "unfold" ]]; then