Add ability to "block" a task ("t.sh b <id>")
This commit is contained in:
parent
0e8e774b69
commit
8ab939ac84
107
t.sh
107
t.sh
|
@ -281,10 +281,15 @@ function confirm() {
|
||||||
|
|
||||||
function loadtask() {
|
function loadtask() {
|
||||||
local uid sum checked folded desc file id parent res i cats
|
local uid sum checked folded desc file id parent res i cats
|
||||||
|
local blockreason
|
||||||
|
|
||||||
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:/ { 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); }')
|
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); } /^REQUEST-STATUS:4.1;/ { sub("REQUEST-STATUS:4.1;",""); printf("breason©%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 == "NEEDS-ACTION") { checked=3; } else if (stat == "IN-PROCESS") { checked = 1 } } END { printf("checked©%d©folded©%d\n",checked,folded); }')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
toadd2="REQUEST-STATUS:4.1;$reason"
|
||||||
|
|
||||||
IFS='©'
|
IFS='©'
|
||||||
read -ra tok <<< "$res"
|
read -ra tok <<< "$res"
|
||||||
|
@ -317,6 +322,8 @@ dblog "process token '${tok[$i]}'"
|
||||||
sum="${tok[$((i + 1))]}"
|
sum="${tok[$((i + 1))]}"
|
||||||
elif [[ ${tok[$i]} == "cats" ]]; then
|
elif [[ ${tok[$i]} == "cats" ]]; then
|
||||||
cats="${tok[$((i + 1))]}"
|
cats="${tok[$((i + 1))]}"
|
||||||
|
elif [[ ${tok[$i]} == "breason" ]]; then
|
||||||
|
blockreason="${tok[$((i + 1))]}"
|
||||||
elif [[ ${tok[$i]} == "desc" ]]; then
|
elif [[ ${tok[$i]} == "desc" ]]; then
|
||||||
desc="${tok[$((i + 1))]}"
|
desc="${tok[$((i + 1))]}"
|
||||||
elif [[ ${tok[$i]} == "parent" ]]; then
|
elif [[ ${tok[$i]} == "parent" ]]; then
|
||||||
|
@ -334,6 +341,7 @@ dblog "process token '${tok[$i]}'"
|
||||||
taskid[$id]=$id
|
taskid[$id]=$id
|
||||||
tasksum[$id]=$sum
|
tasksum[$id]=$sum
|
||||||
taskcats[$id]=$cats
|
taskcats[$id]=$cats
|
||||||
|
taskblockreason[$id]="$blockreason"
|
||||||
taskdesc[$id]=$desc
|
taskdesc[$id]=$desc
|
||||||
taskchecked[$id]=$checked
|
taskchecked[$id]=$checked
|
||||||
taskfolded[$id]=$folded
|
taskfolded[$id]=$folded
|
||||||
|
@ -344,6 +352,7 @@ dblog "process token '${tok[$i]}'"
|
||||||
echo "taskid[$id]=$id"
|
echo "taskid[$id]=$id"
|
||||||
echo "tasksum[$id]=$sum"
|
echo "tasksum[$id]=$sum"
|
||||||
echo "taskcats[$id]=$cats"
|
echo "taskcats[$id]=$cats"
|
||||||
|
echo "taskblockreason[$id]=$blockreason"
|
||||||
echo "taskdesc[$id]=$desc"
|
echo "taskdesc[$id]=$desc"
|
||||||
echo "taskchecked[$id]=$checked"
|
echo "taskchecked[$id]=$checked"
|
||||||
echo "taskfolded[$id]=$folded"
|
echo "taskfolded[$id]=$folded"
|
||||||
|
@ -377,7 +386,8 @@ function marknotdone() {
|
||||||
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"
|
#sed -i '/^COMPLETED:/d;/^STATUS:/d;/PERCENT-COMPLETE:/d' "$file"
|
||||||
|
clearstatus "$file"
|
||||||
sedrv=$((sedrv + $?))
|
sedrv=$((sedrv + $?))
|
||||||
set_lastmodified $uid
|
set_lastmodified $uid
|
||||||
sedrv=$((sedrv + $?))
|
sedrv=$((sedrv + $?))
|
||||||
|
@ -868,6 +878,75 @@ function unfold() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function clearstatus() {
|
||||||
|
local file
|
||||||
|
file="$1"
|
||||||
|
[[ -e $file ]] && sed -i '/^COMPLETED:/d;/^STATUS:COMPLETED/d;/PERCENT-COMPLETE:/d;/^STATUS:IN-PROCESS:/d;/^STATUS:NEEDS-ACTION/d;/^$/d;/^REQUEST-STATUS:/d;' "$file"
|
||||||
|
}
|
||||||
|
|
||||||
|
function markblocked() { # $1=uid $2=reason
|
||||||
|
local uid sedrv rv file toadd1 str now
|
||||||
|
local children childuid ischild noun id
|
||||||
|
uid=$1
|
||||||
|
reason="$2"
|
||||||
|
id=$(getid $uid)
|
||||||
|
[[ $# -gt 1 ]] && ischild=1 || ischild=0
|
||||||
|
[[ $ischild -eq 1 ]] && noun=subtask || noun=task
|
||||||
|
# already in progress?
|
||||||
|
if [[ ${taskchecked[$id]} -eq 3 ]]; then
|
||||||
|
if [[ ${taskblockreason[$id]} == "$reason" ]]; then
|
||||||
|
error "$noun #${id} is already blocked"
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
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;/STATUS:IN-PROCESS:/d;/STATUS:NEEDS-ACTION/d' "$file"
|
||||||
|
clearstatus "$file"
|
||||||
|
# then add blocked
|
||||||
|
toadd1="STATUS:NEEDS-ACTION"
|
||||||
|
sed -i "/$str/i $toadd1\n" "$file"
|
||||||
|
sedrv=$?
|
||||||
|
if [[ -n $reason ]]; then
|
||||||
|
toadd2="REQUEST-STATUS:4.1;$reason"
|
||||||
|
sed -i "/$str/i $toadd2\n" "$file"
|
||||||
|
sedrv=$((sedrv + $?))
|
||||||
|
fi
|
||||||
|
set_lastmodified $uid
|
||||||
|
sedrv=$((sedrv + $?))
|
||||||
|
if [[ $sedrv -eq 0 ]]; then
|
||||||
|
local txt
|
||||||
|
txt="Marked $noun #${id} as blocked"
|
||||||
|
|
||||||
|
if [[ -n $reason ]]; then
|
||||||
|
txt="${txt} due to ${BOLD}$reason$PLAIN"
|
||||||
|
fi
|
||||||
|
txt="${txt}."
|
||||||
|
action "$txt"
|
||||||
|
processed="$processed ${uid} "
|
||||||
|
loadtask "$file"
|
||||||
|
rv=0
|
||||||
|
# dont block children
|
||||||
|
#children=$(getchildren $uid)
|
||||||
|
#for childuid in ${children}; do
|
||||||
|
# markblocked $childuid noprint
|
||||||
|
# rv=$((rv + $?))
|
||||||
|
#done
|
||||||
|
#echo "file: $file"
|
||||||
|
#cat $file
|
||||||
|
else
|
||||||
|
failed="$failed ${uid} "
|
||||||
|
error "failed to mark $noun #${id} as blocked"
|
||||||
|
rv=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
return $rv
|
||||||
|
}
|
||||||
|
|
||||||
function markinprogress() {
|
function markinprogress() {
|
||||||
local uid sedrv rv file toadd1 str now
|
local uid sedrv rv file toadd1 str now
|
||||||
local children childuid ischild noun id
|
local children childuid ischild noun id
|
||||||
|
@ -886,7 +965,8 @@ function markinprogress() {
|
||||||
file="$dir/$uid.vcf"
|
file="$dir/$uid.vcf"
|
||||||
|
|
||||||
# first remove any existing completion
|
# first remove any existing completion
|
||||||
sed -i '/^COMPLETED:/d;/^STATUS:COMPLETED/d;/PERCENT-COMPLETE:/d' "$file"
|
#sed -i '/^COMPLETED:/d;/^STATUS:COMPLETED/d;/PERCENT-COMPLETE:/d;/STATUS:NEEDS-ACTION/d;' "$file"
|
||||||
|
clearstatus "$file"
|
||||||
|
|
||||||
# then add partial completion
|
# then add partial completion
|
||||||
toadd1="STATUS:IN-PROCESS"
|
toadd1="STATUS:IN-PROCESS"
|
||||||
|
@ -1062,10 +1142,13 @@ function showit() {
|
||||||
local notecol bcol bl br space pre end
|
local notecol bcol bl br space pre end
|
||||||
local showkids
|
local showkids
|
||||||
local reset catstr catcol lrogcol
|
local reset catstr catcol lrogcol
|
||||||
|
local blockedcol blockedrcol blockstr
|
||||||
|
|
||||||
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"
|
progcol="\033[38;2;212;0;255m"
|
||||||
|
blockedcol="\033[38;2;212;0;0m"
|
||||||
|
blockedrcol="$blockedcol$BOLD"
|
||||||
|
|
||||||
showkids=1
|
showkids=1
|
||||||
if [[ $1 == "--nochildren" ]]; then
|
if [[ $1 == "--nochildren" ]]; then
|
||||||
|
@ -1105,6 +1188,10 @@ function showit() {
|
||||||
char="&"
|
char="&"
|
||||||
charcol="$progcol"
|
charcol="$progcol"
|
||||||
end="${progcol}...${reset}"
|
end="${progcol}...${reset}"
|
||||||
|
elif [[ ${taskchecked[$id]} -eq 3 ]]; then
|
||||||
|
char="🛑"
|
||||||
|
charcol="$blockedcol"
|
||||||
|
col="$blockedcol"
|
||||||
else
|
else
|
||||||
char=" "
|
char=" "
|
||||||
charcol="$GREEN"
|
charcol="$GREEN"
|
||||||
|
@ -1135,6 +1222,11 @@ function showit() {
|
||||||
pre=""
|
pre=""
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ -z ${taskblockreason[$id]} ]]; then
|
||||||
|
blockstr=""
|
||||||
|
else
|
||||||
|
blockstr="${blockedrcol} (${taskblockreason[$id]}$reset$blockedrcol)"
|
||||||
|
fi
|
||||||
if [[ -z ${taskcats[$id]} ]]; then
|
if [[ -z ${taskcats[$id]} ]]; then
|
||||||
catstr=""
|
catstr=""
|
||||||
else
|
else
|
||||||
|
@ -1156,7 +1248,7 @@ function showit() {
|
||||||
ilev=$(getindentlevel $id)
|
ilev=$(getindentlevel $id)
|
||||||
|
|
||||||
printf "$reset"
|
printf "$reset"
|
||||||
printf "$bcol$bl$reset$charcol%s$reset$bcol$br$reset ${col}${pre}%s$end${reset}${catstr}${reset}\n" "${char}" "${tasksum[$id]}"
|
printf "$bcol$bl$reset$charcol%s$reset$bcol$br$reset ${col}${pre}%s$end${reset}${blockstr}${reset}${catstr}${reset}\n" "${char}" "${tasksum[$id]}"
|
||||||
nextline
|
nextline
|
||||||
|
|
||||||
if [[ ! -z ${taskdesc[$id]} ]]; then
|
if [[ ! -z ${taskdesc[$id]} ]]; then
|
||||||
|
@ -1528,6 +1620,7 @@ addcmd "toggle" "toggle <id>" "Fold/Unfold a parent task" "toggle|z|zz" SUPPORTS
|
||||||
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 "inprogress" "inprogress <taskid>" "Mark a task as in progress" "inprogress|progress|inp|prog|i|p" SUPPORTS_ALL
|
||||||
|
addcmd "blocked" "blocked <taskid>" "Mark a task as blocked" "blocked|block|b" 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"
|
||||||
|
@ -1729,6 +1822,10 @@ elif [[ $mode == "left" ]]; then
|
||||||
uid=$(getuid_witherror $1)
|
uid=$(getuid_witherror $1)
|
||||||
shift
|
shift
|
||||||
move_left $uid
|
move_left $uid
|
||||||
|
elif [[ $mode == "blocked" ]]; then
|
||||||
|
uid=$(getuid_witherror $1)
|
||||||
|
shift
|
||||||
|
markblocked $uid "$*"
|
||||||
elif [[ $mode == "right" ]]; then
|
elif [[ $mode == "right" ]]; then
|
||||||
pid=$BASH_ARGV
|
pid=$BASH_ARGV
|
||||||
if [[ $puid != "-" ]]; then
|
if [[ $puid != "-" ]]; then
|
||||||
|
@ -1803,6 +1900,8 @@ else
|
||||||
match=1
|
match=1
|
||||||
elif [[ $mode == "inprogress" && ${taskchecked[$id]} -ne 1 ]]; then
|
elif [[ $mode == "inprogress" && ${taskchecked[$id]} -ne 1 ]]; then
|
||||||
match=1
|
match=1
|
||||||
|
elif [[ $mode == "blocked" && ${taskchecked[$id]} -ne 3 ]]; then
|
||||||
|
match=1
|
||||||
elif [[ $mode == "list" && $hasparent -eq 0 ]]; then
|
elif [[ $mode == "list" && $hasparent -eq 0 ]]; then
|
||||||
match=1
|
match=1
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue