hlfw.ca

task

ref: 70304f799207e7dc84dbe877cbb9e3b8eeec2ee1
dir: /add/

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

fn editmsg{
	if(! test -s $msgfile.tmp){
		>$msgfile.tmp {
			echo '#' $synopsis
			echo ''
		}
		edit=1
	}
	
	if(! ~ $#edit 0){
		if(~ $#editor 0){
			# store current, run editor, then write change to final
			cp $msgfile.tmp $msgfile
			editor=hold
		}
		$editor $mw
sgfile.tmp
	}
	if(! test -s $msgfile.tmp){
		echo 'nothing to add' >[1=2]
		exit 'message'
	}
	## TODO: Check if we have hold as editor, otherwise just cp here
	cat $msgfile.tmp >> $msgfile
}

fn gettag{
	# Fetch he last numerical tag in the dir
	tag=`{ls .task/*[0-9] | tail -1 | sed 's#.task/##'}
	if(! ~ $#change 0)
		tag=$change
	if not
		tag=`{echo $tag^+1 | bc}
}

fn finish{
	cp $msgfile .task/$tag
	# TODO: . common.rc to set $project, as it's useful for our outputs
	#echo '$project:$tag'
}

fn sigexit{
	if(! ~ $#msgfile 0)
		rm -f $msgfile
	if(! ~ $#msgfile.tmp 0)
		rm -f $msgfile.tmp
}

flagfmt='c:change change, e:edit'; args='[msg ...]'
eval `''{aux/getflags $*} || exec aux/usage

msgfile=/tmp/task.$pid

# Bit o messy initialization, but that's ok.
if(! ~ $#* 0)
	synopsis=`{echo $*}
if(! ~ $#change 0){
	edit=1
	if(test -s .task/$change){
		if(! ~ $#synopsis 0){
			echo '#' $synopsis > $msgfile.tmp
			tail +2 .task/$change >> $msgfile.tmp
		}
		if not
			cat .task/$change > $msgfile.tmp
	}
	if not {
		echo 'no task found for ' $change >[1=2]
		exit 'missing'
	}
}

@{
	flag e +
	gettag
	editmsg
	finish
} || echo 'could not write task:' $status >[1=2]
exit ''