hlfw.ca

task

ref: d0908dd592062bc347372c3edc6f464a1af00c48
dir: /walk/

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

# S == Started, not blocked
# B == Not started, blocked
# A == Attempted, blocked
# N == Not started, Not blocked
# D == Done
fn printtask {
	tag=`{echo $1 | sed 's#.task/##'}
	started=`{read}
	blocked=`{read}
	finished=`{read}
	synopsis=`{read}
	flag=()
	if (! ~ $finished 0)
		flag=D
	if not if (~ $started 0) {
		if (~ $blocked 0)
			flag=N
		if not
			flag=B
	}
	if not {
		if (~ $blocked 0)
			flag=S
		if not
			flag=A
	}
	if(~ $#quiet 0){
		if (echo $flags | grep -s $flag)
			if(~ $#chars 0)
				echo $flag $synopsis
			if not
				echo $synopsis
	}
	echo -n ''
}

fn checktask {
	awk '
	function isblocked(file, line){
		while((getline line < file) > 0) {
			if (line ~ /^\[ \]/) {
				close(file)
				return 1
			}
		}
		close(file)
		return 0
	}

	function handlelink(line, link) {
		link=substr(line, 4)
		gsub(/^ *| *$/, "", link)
		if(link != FILENAME){
			return isblocked(link)
		}
		return 0
	}

	BEGIN {
		started = 0
		blocked = 0
		finished = 1
		synopsis = "No description"
	}
	
	/^# / {
		split($0, header, "#")
		synopsis = header[2]
	}

	/^\[x\]/ {
		started = 1
	}

	/^\[ \]/ {
		finished = 0
	}

	/ - \// {
		blocked += handlelink($0)
	}

	END {
		# Listen to flags to see if we print this line
		printf "%s\n%s\n%s\n%s", started, blocked, finished, synopsis
	}
	' $*
}

fn parselist {
	for (t in $tasks)
		cat $t | checktask | printtask $t
}

fn mklist {
	if(test -d .task)
		tasks=`{ls .task}
	if not {
		echo "No project found in directory" >[1=2]
		exit 'project'
	}
}

tasks=()
flagfmt='c:chars, q:quiet, f:flags flags'; args='[projects ...]'
eval `''{aux/getflags $*} || exec aux/usage

if (~ $#flags 0)
	flags=DNS
@{
	flag e +
	mklist
	parselist
} || echo 'walk failed:' $status >[1=2]
exit ''