hlfw.ca

task

Download patch

ref: 634bc3cf821b09e05edf60507cc29dd4ccc49a59
parent: 7ff209324645dddf92a9f15045b21c62a0a4518a
author: Michael Misch <michaelmisch1985@gmail.com>
date: Thu Aug 29 07:41:36 PDT 2024

Update show's pretty print

--- a/README.md
+++ b/README.md
@@ -30,6 +30,8 @@
 
 *Blocked tasks have a child task that requires completing before they can be completed
 
+`pro/show` prints a	formatted task to stdout, when passed -r it will print the raw task file
+
 ## TODO
 
 - `pro/walk` implementation
--- a/mkfile
+++ b/mkfile
@@ -8,6 +8,7 @@
 	init\
 	task\
 	rm\
+	show\
 	walk\
 
 OFILES=\
--- a/show
+++ b/show
@@ -2,14 +2,55 @@
 rfork ne
 
 fn gettags {
-	# Push to showlist
-	for(a in $*)
+	for(a in $pathlist)
 		if(test -s .pro/task/$a)
-			showlist=($showlist $a)
+			showlist=($showlist .pro/task/$a)
 }
 
 fn pretty {
+	awk '
+	BEGIN {
+		total = 0
+		completed = 0
+	}
 
+	# Header
+	NR == 1 {
+		split($0, header, "#")
+		content = header[2]
+		gsub(/^ */, "", content)
+		split(content, parts, " ")
+
+		tag = ""
+		after = ""
+		before = ""
+
+		for (i=1; i<=length(parts); i++) {
+			if (parts[i] == "tag:") tag = parts[i+1]
+			if (parts[i] == "after:") after = parts[i+1]
+			if (parts[i] == "before:") before = parts[i+1]
+		}
+
+		printf("tag: %s", tag)
+		if(before != "") printf(", before: %s", before)
+		if(after != "") printf(", after: %s", after)
+		print "\n"
+	}
+
+	# Checklist percentages
+	/^\[[ x]\]/ {
+		print $0
+		total++
+		if ($0 ~ /^\[x\]/) completed++
+	}
+
+	END {
+		if (total > 0) {
+			percentage = (completed / total) * 100
+			printf("Completion: %.1f%% (%d/%d)\n", percentage, completed, total)
+		}
+	}
+	' $*
 }
 
 fn showtask {
@@ -17,15 +58,16 @@
 		if (~ $#raw 1)
 			cat $m
 		if not
-			pretty $m
-		}
+			cat $m | pretty
+	}
+	# percentages
 }
 
 # Just pretty print a task, nothing to it
 flagfmt='r:raw'; args='[tags ...]'
 eval `''{aux/getflags $*} || exec aux/usage
-
 showlist=()
+pathlist=$*
 
 @{
 	gettags