hlfw.ca

task

ref: a76c9468ca5956257e6d1b6720716ab2df65a205
dir: /show/

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

fn gettags {
	for(a in $pathlist)
		if(test -s .task/$a)
			showlist=($showlist .task/$a)
}

fn pretty {
	awk '
	BEGIN {
		total = 0
		completed = 0
	}

	NR == 1 {
		print $0
	}

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