hlfw.ca

task

ref: e026625830c18a358a485d7c34002d3f853cac55
dir: /show/

View raw version
#!/bin/rc -e
rfork ne

fn gettags {
	for(a in $pathlist)
		if(test -s .pro/task/$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 {
	for(m in $showlist){
		if (~ $#raw 1)
			cat $m
		if not
			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
	showtask
} || echo 'unable to show given tags:' $status >[1=2]
exit ''