diff --git a/t.sh b/t.sh index e14dc46..56c3220 100755 --- a/t.sh +++ b/t.sh @@ -1103,14 +1103,43 @@ function addcmd() { # name usage description alt1|alt2|etc supportsall fi } -function getchildren() { +function sortuidlist() { # sort a list of task uids by task summng aries + local unsorted uidandsum withnl sorted_arr sorted unsorted_arr uid + unsorted="$1" + + # change "123 456 789" to + # ("123#do something" "234#other task" "789#something#) + unsorted_arr="" + for uid in ${unsorted}; do + id=$(getid $uid) + unsorted_arr+=("${taskuid[$id]}#${tasksum[$id]}") + done + IFS=$'\n' + withnl=("${unsorted_arr[*]}") + sorted_arr=($(sort -df -t '#' -k2 <<<"${withnl[*]}")) + sorted="" + for uidandsum in ${sorted_arr[@]}; do + sorted="$sorted ${uidandsum%#*}" + done + unset IFS + echo "$sorted" +} + +function getchildren() { # parentuid local uid childuid children id uid=$1 children="" for id in ${!taskid[@]}; do - [[ ${taskparent[$id]} == $uid ]] && children="$children ${taskuid[$id]}" + if [[ ${taskparent[$id]} == $uid ]]; then + children="$children ${taskuid[$id]}" + fi done [[ -z $children ]] && return 1 + + + if [[ $WANTSORT -eq 1 ]]; then + children=$(sortuidlist "$children") + fi echo "$children" return 0 } @@ -1419,8 +1448,9 @@ DEBUG=0 TESTMODE=0 AUTOSYNC=0 CALID=$(cat "$confdir/defaultcal") +WANTSORT=0 -ARGS="fhic:dstyl:r:" +ARGS="fhic:dsStyl:r:" while getopts "$ARGS" i; do case "$i" in h) @@ -1446,6 +1476,9 @@ while getopts "$ARGS" i; do s) AUTOSYNC=1 ;; + S) + WANTSORT=1 + ;; t) DEBUG=1 TESTMODE=1 @@ -1647,6 +1680,9 @@ else uids="$uids ${taskuid[$id]}" fi done + if [[ $WANTSORT -eq 1 ]]; then + uids=$(sortuidlist "$uids") + fi if [[ ! $mode =~ $passive_modes ]]; then info "About to run '$mode' on the following tasks:" needtitle=0