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