commit 7bb89f78cac36bec5cc0ade89e3e98a115f302e0
from: Sven M. Hallberg <pesco@khjk.org>
date: Sun Oct 06 07:45:45 2019 UTC

add -s (summarize)

commit - d43c29463da4ed478723a69056f54115f5355978
commit + 7bb89f78cac36bec5cc0ade89e3e98a115f302e0
blob - d70c7b9f3b934eeaa805a2d7bca9beb201676075
blob + 43438e323fb288c806dddba832adcce276da5466
--- painlist
+++ painlist
@@ -157,7 +157,34 @@ format='
             if(npost) printf(", %d postponed", npost)
             print reset()
         }
+    }
+'
+
+# awk program to summarize totals
+summarize='
+    function context(s, arr) {
+        delete arr
+        while(match(s, /[[:space:]][#@][a-zA-Z0-9]+/)) {
+            t = substr(s, RSTART+2, RLENGTH-2)
+            s = substr(s, RSTART+RLENGTH)
+            arr[t] = 1;
+        }
+    }
+
+    {
+        if(substr($0,7,1) == "^") { next }
+        total += $1
+
+        context($0, ctx)
+        for(t in ctx) { sum[t] += $1 }
     }
+
+    END {
+        printf("%5.1f total", total)
+        for(t in sum)
+                printf("  %.1f %s", sum[t], t)
+        print ""
+    }
 '
 
 if test -t 1  # is stdout a tty?
@@ -166,9 +193,9 @@ then
     maxitems=$(($(tput li) - 5))
 fi
 
-args=`getopt npvt:l: $*`
+args=`getopt npsvt:l: $*`
 if [ $? -ne 0 ]; then
-    echo "usage: $0 [-npv] [-t THRESHOLD] [-l MAX] [pattern]"
+    echo "usage: $0 [-npsv] [-t THRESHOLD] [-l MAX] [pattern]"
     exit 1
 fi
 set -- $args
@@ -176,6 +203,7 @@ while [ $# -ne 0 ]; do
     case "$1" in
         -n) nocolor=1; shift;;
         -p) format='{print}'; shift;;
+        -s) format="$summarize"; shift;;
         -t) theta="$2"; shift; shift;;
         -v) invert=1; shift;;
         -l) maxitems="$2"; shift; shift;;