Add "zz" alias for "toggle open/close"

Add "mv <id> -" format to move task to toplevel
Fix message saying "completed" when marking task as NOT completed.
Fix cosmetic double-print bug when marking a parent+children done
This commit is contained in:
Rob Pearce 2021-09-05 09:51:21 +10:00
parent 6d22982bbb
commit 82c3860e65
1 changed files with 94 additions and 43 deletions

79
t.sh
View File

@ -353,7 +353,7 @@ function marknotdone() {
set_lastmodified $uid set_lastmodified $uid
sedrv=$((sedrv + $?)) sedrv=$((sedrv + $?))
if [[ $sedrv -eq 0 ]]; then if [[ $sedrv -eq 0 ]]; then
action "Marked $noun #${id} as completed." action "Marked $noun #${id} as unfinished."
processed="$processed ${uid} " processed="$processed ${uid} "
loadtask $file loadtask $file
rv=0 rv=0
@ -490,12 +490,20 @@ function move_right() { # move_right uid new_parent
id=$(getid $uid) id=$(getid $uid)
rv=0 rv=0
newparent=$2 newparent=$2
if [[ $newparent == "-" ]]; then
newparent=""
newparentid=""
else
newparentid=$(getid $newparent) newparentid=$(getid $newparent)
fi
rv=0 rv=0
taskparent[$id]="$newparent" taskparent[$id]="$newparent"
file=$dir/$uid.vcf file=$dir/$uid.vcf
if [[ -z $newparent ]]; then
sed -i "/^RELATED-TO.*/d" $file
sedrv=$?
else
if grep -q ^RELATED-TO $file; then if grep -q ^RELATED-TO $file; then
sed -i "s/^RELATED-TO.*/RELATED-TO;RELTYPE=PARENT:${taskparent[$id]}/" $file sed -i "s/^RELATED-TO.*/RELATED-TO;RELTYPE=PARENT:${taskparent[$id]}/" $file
sedrv=$? sedrv=$?
@ -505,17 +513,28 @@ function move_right() { # move_right uid new_parent
sed -i "/$str/i $toadd\n" $file sed -i "/$str/i $toadd\n" $file
sedrv=$? sedrv=$?
fi fi
fi
set_lastmodified $uid set_lastmodified $uid
sedrv=$((sedrv + $?)) sedrv=$((sedrv + $?))
if [[ $sedrv -eq 0 ]]; then if [[ $sedrv -eq 0 ]]; then
action "Shifted task #${id} underneath #${newparentid} ('${tasksum[$newparentid]}')." if [[ -z $newparent ]]; then
str="to toplevel."
else
str="underneath #${newparentid} ('${tasksum[$newparentid]}')."
fi
action "Shifted task #${id} $str"
loadtask $file loadtask $file
showit ${taskparent[$id]} $uid showit ${taskparent[$id]} $uid
rv=0 rv=0
else else
error "Failed to shift task #${id} under #${newparentid}." if [[ -z $newparent ]]; then
str="to toplevel."
else
str="under #${newparentid}."
fi
error "Failed to shift task #${id} $str"
rv=1 rv=1
fi fi
@ -1039,13 +1058,20 @@ function addcmd() { # name usage description alt1|alt2|etc supportsall
eval "desc_${cmd}=\"${desc}\"" eval "desc_${cmd}=\"${desc}\""
eval "words_${cmd}=\"${alts}\"" eval "words_${cmd}=\"${alts}\""
if [[ $# -ge 5 ]]; then if [[ $* == *SUPPORTS_ALL* ]]; then
if [[ -z $modes_that_support_all ]]; then if [[ -z $modes_that_support_all ]]; then
modes_that_support_all="$cmd" modes_that_support_all="$cmd"
else else
modes_that_support_all="$modes_that_support_all|$cmd" modes_that_support_all="$modes_that_support_all|$cmd"
fi fi
fi fi
if [[ $* == *PASSIVE* ]]; then
if [[ -z $passive_modes ]]; then
passive_modes="$cmd"
else
passive_modes="$passive_modes|$cmd"
fi
fi
} }
function getchildren() { function getchildren() {
@ -1156,15 +1182,16 @@ indentamt=4
needsave=0 needsave=0
mode=list mode=list
modes_that_support_all="" modes_that_support_all=""
passive_modes="" # modes that do not change data
# for pager # for pager
printed=0 printed=0
rows=$(tput lines) rows=$(tput lines)
addcmd "list" "list [id1] .. [idX]" "List [just the specified] tasks" "list|ls|show" addcmd "list" "list [id1] .. [idX]" "List [just the specified] tasks" "list|ls|show" SUPPORTS_ALL PASSIVE
addcmd "fold" "fold <id>" "Fold a parent task (hide its children)" "fold|f|zc" SUPPORTS_ALL addcmd "fold" "fold <id>" "Fold a parent task (hide its children)" "fold|f|zc" SUPPORTS_ALL
addcmd "unfold" "unfold <id>" "Unfold a parent task (show its children)" "unfold|u|zo" SUPPORTS_ALL addcmd "unfold" "unfold <id>" "Unfold a parent task (show its children)" "unfold|u|zo" SUPPORTS_ALL
addcmd "toggle" "toggle <id>" "Fold/Unfold a parent task" "toggle|z" 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 "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"
@ -1177,7 +1204,7 @@ addcmd "note" "note <id> <notes>" "Change notes for given task" "note|desc|descr
addcmd "tag" "tag <id> <tag>" "Add a tag to the given task" "tag|t" addcmd "tag" "tag <id> <tag>" "Add a tag to the given task" "tag|t"
addcmd "untag" "untag <id> <tag>" "Remove a tag from the given task" "untag|ut" addcmd "untag" "untag <id> <tag>" "Remove a tag from the given task" "untag|ut"
addcmd "sync" "sync" "Sync tasks using vdirsyncer" "sync" addcmd "sync" "sync" "Sync tasks using vdirsyncer" "sync"
addcmd "view" "view <id>" "Show detailed info for given task" "v|view|info|vcal" addcmd "view" "view <id>" "Show detailed info for given task" "v|view|info|vcal" PASSIVE
DEBUG=0 DEBUG=0
TESTMODE=0 TESTMODE=0
@ -1281,7 +1308,11 @@ elif [[ $mode == "left" ]]; then
move_left $uid move_left $uid
elif [[ $mode == "right" ]]; then elif [[ $mode == "right" ]]; then
uid=$(getuid_witherror $1) uid=$(getuid_witherror $1)
if [[ $2 == "-" ]]; then
puid="-"
else
puid=$(getuid_witherror $2 "parent task") puid=$(getuid_witherror $2 "parent task")
fi
shift 2 shift 2
move_right $uid $puid move_right $uid $puid
elif [[ $mode == "view" ]]; then elif [[ $mode == "view" ]]; then
@ -1308,10 +1339,12 @@ else
uids="" uids=""
if [[ -z $filter ]]; then if [[ -z $filter ]]; then
for id in ${!taskid[@]}; do #for id in ${!taskid[@]}; do
[[ -z ${taskparent[$id]} ]] && uids="$uids ${taskuid[$id]}" # [[ -z ${taskparent[$id]} ]] && uids="$uids ${taskuid[$id]}"
done #done
elif [[ $filter == "all" ]]; then filter=all
fi
if [[ $filter == "all" ]]; then
na=0 na=0
if [[ ! $mode =~ $modes_that_support_all ]]; then if [[ ! $mode =~ $modes_that_support_all ]]; then
error "Command '$mode' doesn't support 'all'" error "Command '$mode' doesn't support 'all'"
@ -1322,6 +1355,7 @@ else
match=0 match=0
uid=$(getuid $id) uid=$(getuid $id)
children=$(getchildren $uid) children=$(getchildren $uid)
[[ -z ${taskparent[$id]} ]] && hasparent=0 || hasparent=1
[[ -z $children ]] && haschildren=0 || haschildren=1 [[ -z $children ]] && haschildren=0 || haschildren=1
if [[ $mode == "fold" && $haschildren -eq 1 && ${taskfolded[$id]} -ne 1 ]]; then if [[ $mode == "fold" && $haschildren -eq 1 && ${taskfolded[$id]} -ne 1 ]]; then
match=1 match=1
@ -1333,12 +1367,15 @@ else
match=1 match=1
elif [[ $mode == "notdone" && ${taskchecked[$id]} -eq 1 ]]; then elif [[ $mode == "notdone" && ${taskchecked[$id]} -eq 1 ]]; then
match=1 match=1
elif [[ $mode == "list" && $hasparent -eq 0 ]]; then
match=1
fi fi
if [[ $match -eq 1 ]]; then if [[ $match -eq 1 ]]; then
uids="$uids ${taskuid[$id]}" uids="$uids ${taskuid[$id]}"
fi fi
done done
if [[ ! $mode =~ $passive_modes ]]; then
info "About to run '$mode' on the following tasks:" info "About to run '$mode' on the following tasks:"
needtitle=0 needtitle=0
for uid in $uids; do for uid in $uids; do
@ -1363,6 +1400,7 @@ else
action "Aborted." action "Aborted."
exit 1 exit 1
fi fi
fi
elif [[ $filter =~ ^[0-9\ ]+$ ]]; then elif [[ $filter =~ ^[0-9\ ]+$ ]]; then
# list of task IDs # list of task IDs
for wantid in $filter; do for wantid in $filter; do
@ -1380,7 +1418,6 @@ else
fi fi
needtitle=1 needtitle=1
if [[ -z $uids ]]; then if [[ -z $uids ]]; then
error "no matching tasks found." error "no matching tasks found."
exit 1 exit 1
@ -1409,8 +1446,22 @@ else
if [[ $mode == "del" ]]; then if [[ $mode == "del" ]]; then
delq_process delq_process
fi fi
# show results # remove duplicates where list contains both parent
# and child of parent
if [[ ! -z $processed ]]; then if [[ ! -z $processed ]]; then
for uid in ${processed}; do
thisid=$(getid $uid)
parentuid=${taskparent[$thisid]}
# is this NOT the child of something in the list
if [[ -z $parentuid || $processed != *$parentuid* ]]; then
newprocessed="$newprocessed $uid"
fi
done
processed="$newprocessed"
fi
if [[ ! -z $processed ]]; then
# show results
for uid in ${processed}; do for uid in ${processed}; do
showit $uid showit $uid
done done