hlfw.ca

task

ref: 156d0b3f8f89cb2b8f5ea79304dc63c24b6d1cda
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 = ""
		child = ""
		parent = ""

		for (i=1; i<=length(parts); i++) {
			if (parts[i] == "tag:") tag = parts[i+1]
			if (parts[i] == "child:") child = parts[i+1]
			if (parts[i] == "parent:") parent = parts[i+1]
		}

		printf("tag: %s", tag)
		if(bparent != "") printf(", parent: %s", parent)
		if(child != "") printf(", child: %s", child)
		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
	}
	# TODO: Show child percentages
}

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 ''