Added inprogress command

This commit is contained in:
Rob Pearce 2021-11-25 20:02:23 +11:00
parent 1c24822940
commit af108cbfc8
1 changed files with 69 additions and 11 deletions

80
t.sh
View File

@ -284,7 +284,7 @@ function loadtask() {
dblog "open $1" dblog "open $1"
file="$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='©' IFS='©'
read -ra tok <<< "$res" read -ra tok <<< "$res"
@ -376,7 +376,8 @@ function marknotdone() {
return 1 return 1
fi fi
file="$dir/$uid.vcf" 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 + $?)) sedrv=$((sedrv + $?))
set_lastmodified $uid set_lastmodified $uid
sedrv=$((sedrv + $?)) sedrv=$((sedrv + $?))
@ -820,6 +821,52 @@ function unfold() {
return $rv 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() { function markdone() {
local uid sedrv rv file toadd1 toadd2 toadd3 str now local uid sedrv rv file toadd1 toadd2 toadd3 str now
local children childuid ischild noun id local children childuid ischild noun id
@ -828,7 +875,7 @@ function markdone() {
[[ $# -gt 1 ]] && ischild=1 || ischild=0 [[ $# -gt 1 ]] && ischild=1 || ischild=0
[[ $ischild -eq 1 ]] && noun=subtask || noun=task [[ $ischild -eq 1 ]] && noun=subtask || noun=task
# already complete? # already complete?
if [[ ${taskchecked[$id]} -eq 1 ]]; then if [[ ${taskchecked[$id]} -eq 2 ]]; then
error "$noun #${id} is already completed" error "$noun #${id} is already completed"
return 1 return 1
fi fi
@ -968,10 +1015,11 @@ function showit() {
local children nchildren charcol local children nchildren charcol
local notecol bcol bl br space pre end local notecol bcol bl br space pre end
local showkids local showkids
local reset catstr catcol local reset catstr catcol lrogcol
reset="$PLAIN" reset="$PLAIN"
catcol="\033[38;2;255;165;0m" catcol="\033[38;2;255;165;0m"
progcol="\033[38;2;212;0;255m"
showkids=1 showkids=1
if [[ $1 == "--nochildren" ]]; then if [[ $1 == "--nochildren" ]]; then
@ -1001,12 +1049,19 @@ function showit() {
col="$reset" col="$reset"
notecol="$YELLOW" notecol="$YELLOW"
if [[ ${taskchecked[$id]} -eq 1 ]]; then end=""
if [[ ${taskchecked[$id]} -eq 2 ]]; then
char="✓" char="✓"
charcol="$GREEN"
col="$col$STRIKE" col="$col$STRIKE"
notecol="$notecol$STRIKE" notecol="$notecol$STRIKE"
elif [[ ${taskchecked[$id]} -eq 1 ]]; then
char="&"
charcol="$progcol"
end="${progcol}...${reset}"
else else
char=" " char=" "
charcol="$GREEN"
fi fi
if [[ $uid == $hilite ]]; then if [[ $uid == $hilite ]]; then
@ -1014,7 +1069,6 @@ function showit() {
notecol="$notecol$HILITE" notecol="$notecol$HILITE"
fi fi
charcol="$GREEN"
if [[ $nchildren -gt 0 && ${taskfolded[$id]} -eq 1 ]]; then if [[ $nchildren -gt 0 && ${taskfolded[$id]} -eq 1 ]]; then
bcol=$brackfold bcol=$brackfold
bl="(" bl="("
@ -1022,7 +1076,7 @@ function showit() {
#col="$col$FOLDBG" #col="$col$FOLDBG"
space=" " space=" "
pre="" pre=""
end=" $reset$CYAN${BOLD}[$nchildren subtasks]" end=" $end$reset$CYAN${BOLD}[$nchildren subtasks]"
if [[ $char == " " ]]; then if [[ $char == " " ]]; then
char="+" char="+"
charcol="$BOLD$CYAN" charcol="$BOLD$CYAN"
@ -1033,7 +1087,6 @@ function showit() {
br="]" br="]"
space=" " space=" "
pre="" pre=""
end=""
fi fi
if [[ -z ${taskcats[$id]} ]]; then if [[ -z ${taskcats[$id]} ]]; then
@ -1428,6 +1481,7 @@ addcmd "unfold" "unfold <id>" "Unfold a parent task (show its children)" "unfold
addcmd "toggle" "toggle <id>" "Fold/Unfold a parent task" "toggle|z|zz" SUPPORTS_ALL addcmd "toggle" "toggle <id>" "Fold/Unfold a parent task" "toggle|z|zz" SUPPORTS_ALL
addcmd "done" "done <taskid>" "Complete a task" "done|x|complete" SUPPORTS_ALL addcmd "done" "done <taskid>" "Complete a task" "done|x|complete" SUPPORTS_ALL
addcmd "notdone" "notdone <taskid>" "Uncomplete a task" "notdone|o|incomplete|uncomplete|clear" SUPPORTS_ALL addcmd "notdone" "notdone <taskid>" "Uncomplete a task" "notdone|o|incomplete|uncomplete|clear" SUPPORTS_ALL
addcmd "inprogress" "inprogress <taskid>" "Mark a task as in progress" "inprogress|progress|inp|prog|i|p" SUPPORTS_ALL
addcmd "add" "add [parent] <name>" "Add a new task [as subtask of parent]" "a|add|new|create" addcmd "add" "add [parent] <name>" "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 "del" "del [id1] .. [idX]" "Delete given task(s)" "del|rm|delete"
addcmd "cleanup" "cleanup" "Delete all completed tasks" "cleanup|clean|flush|dc" addcmd "cleanup" "cleanup" "Delete all completed tasks" "cleanup|clean|flush|dc"
@ -1647,7 +1701,7 @@ elif [[ $mode == "cleanup" ]]; then
action "Deleting all completed tasks." action "Deleting all completed tasks."
for id in ${!taskuid[@]}; do for id in ${!taskuid[@]}; do
uid=$(getuid $id) uid=$(getuid $id)
[[ ${taskchecked[$id]} -eq 1 ]] && delq_add $uid [[ ${taskchecked[$id]} -eq 2 ]] && delq_add $uid
done done
delq_process delq_process
@ -1688,9 +1742,11 @@ else
elif [[ $mode == "unfold" && ${taskfolded[$id]} -eq 1 ]]; then elif [[ $mode == "unfold" && ${taskfolded[$id]} -eq 1 ]]; then
match=1 match=1
kids="--nochildren" kids="--nochildren"
elif [[ $mode == "done" && ${taskchecked[$id]} -eq 0 ]]; then elif [[ $mode == "done" && ${taskchecked[$id]} -ne 2 ]]; then
match=1 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 match=1
elif [[ $mode == "list" && $hasparent -eq 0 ]]; then elif [[ $mode == "list" && $hasparent -eq 0 ]]; then
match=1 match=1
@ -1767,6 +1823,8 @@ else
markdone $uid markdone $uid
elif [[ $mode == "notdone" ]]; then elif [[ $mode == "notdone" ]]; then
marknotdone $uid marknotdone $uid
elif [[ $mode == "inprogress" ]]; then
markinprogress $uid
elif [[ $mode == "fold" ]]; then elif [[ $mode == "fold" ]]; then
fold $uid fold $uid
elif [[ $mode == "unfold" ]]; then elif [[ $mode == "unfold" ]]; then