hlfw.ca

task

Download patch

ref: f67bb05ee10be20fba693f649a700861edb9da09
parent: d67b1c7ecb14d025f262edbcbab4b92d54f8b397
author: Michael Misch <michaelmisch1985@gmail.com>
date: Fri Aug 30 00:43:34 PDT 2024

Prepare to use nested relationships in task files, clean up tag generation

--- a/README.md
+++ b/README.md
@@ -8,17 +8,13 @@
 
 ## Task files
 
-	# tag: 14 parent: 12 child: 2
 	# A synopsis of the task
 	
 	[ ] some item
 	[ ] some other item
 	[x] some finished item
+	 -  /myproject/2
 
-A parent is a task that cannot be completed until the given task is complete, set by tag. A child is a task that must be completed prior to completing the given task, set by tag.
-
-Task items are flat checkboxes, any hierarchy required can be achieved with parent/child tag relationships between tasks.
-
 ## Commands
 
 `pro/init` is use to create a new barebones project, with no tasks or namespace files. The project will be created with the basename of current directory, or `name` if given.
@@ -27,7 +23,7 @@
 
 (See [this post](https://hlfw.ca/blog/2024-08-24-more-setup.html) for inspiration, and further integration.)
 
- `pro/task` is used to manage or add a task to the graph, usage is similar to git/commit - the hold editor will be used by default, ctrl+d is used to signal completion. `-a $tag` will create the task as a child of `$tag`. `-b $tag` will create the task as a parent of `$tag`. `-c $tag` is used to change an existing task. Passing `-e` will use your default editor instead of hold mode. Any args afterwards will be passed along as the synopsis for the task
+ `pro/task` is used to manage or add a task to the graph, usage is similar to git/commit - the hold editor will be used by default, ctrl+d is used to signal completion. `-c $tag` is used to change an existing task. Passing `-e` will use your default editor instead of hold mode. Any args afterwards will be passed along as the `synopsis` for the task
 
 `pro/rm` removes a given completed task. With `-f`, all matching tags are removed. With `-a`, all completed tags are checked for removal. 
 
@@ -57,17 +53,3 @@
 
 A `pro/fs` could be spun up, given a set of paths that your projects live somewhere within, by default the user $home, and could walk the paths looking for .pro directories.
 - This would allow utilities to query the fs for valid tags and completion states outside of the current project.
-
-## Possible Changes
-
-In task lists, we could infer child/parent relationships with inline linkages. This eliminates some flags, thought building the graph becomes more involved than just parsing headers
-
-	# tag: 10
-	# some task
-	
-	[ ] item to do
-	[x] another one
-	[-] project/11
-	[-] project/12
-
-- uses name of the name of the project, then the tag ID with `[-]` to indicate the linkage
--- a/rm
+++ b/rm
@@ -1,6 +1,10 @@
 #!/bin/rc -e
 rfork ne
 
+fn cleanlinks {
+	# Walk through any related tags, and remove any blockable references
+}
+
 fn checkstate {
 	if(! ~ $#all 0){
 		if(! ~ $#force 0)
@@ -22,8 +26,8 @@
 fn rmtask {
 	for(m in $rmlist){
 		# TODO: when we have multiproject
-		#echo removed $project:$m
-		echo removed $m
+		#echo $project/$m completed
+		echo $m completed
 		rm $m
 	}
 }
@@ -36,5 +40,6 @@
 	flag e +
 	checkstate
 	rmtask
+	cleanlinks
 } || echo 'could not rm task:' $status >[1=2]
 exit ''
--- a/show
+++ b/show
@@ -14,27 +14,8 @@
 		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"
+		print $0
 	}
 
 	# Checklist percentages
--- a/task
+++ b/task
@@ -1,38 +1,38 @@
 #!/bin/rc -e
 rfork ne
 
-# TODO: If we have a synopsis and a change, rewrite our synopsis line as well
 fn editmsg{
 	if(! test -s $msgfile.tmp){
 		>$msgfile.tmp {
-			echo -n '# tag:' $tag
-			if(! ~ $#child 0)
-				echo -n ' child:' $child
-			if(! ~ $#parent 0)
-				echo -n ' parent:' $parent
-			echo '' 
 			echo '#' $synopsis
+			echo ''
 		}
 		edit=1
 	}
+	
 	if(! ~ $#edit 0){
-		if(~ $#editor 0)
+		if(~ $#editor 0){
+			# store current, run editor, then write change to final
+			cp $msgfile.tmp $msgfile
 			editor=hold
+		}
 		$editor $msgfile.tmp
 	}
-	cat $msgfile.tmp >> $msgfile
-	if(! test -s $msgfile){
-		echo 'empty commit message' >[1=2]
+	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{
-	files=`{ls .pro/task/}
+	# Fetch he last numerical tag in the dir
+	tag=`{ls .pro/task/*[0-9] | tail -1 | sed 's#.pro/task/##'}
 	if(! ~ $#change 0)
 		tag=$change
 	if not
-		tag=$#files
+		tag=`{echo $tag^+1 | bc}
 }
 
 fn finish{
@@ -48,16 +48,29 @@
 		rm -f $msgfile.tmp
 }
 
-flagfmt='c:change change, a:child child, b:parent parent, e:edit'; args='[msg ...]'
+flagfmt='c:change change, e:edit'; args='[msg ...]'
 eval `''{aux/getflags $*} || exec aux/usage
 
 msgfile=/tmp/pro-msg.$pid
+
+# Bit o messy initialization, but that's ok.
 if(! ~ $#* 0)
 	synopsis=`{echo $*}
-if(! ~ $#change 0)
-	if(test -s .pro/task/$change)
-		cat .pro/task/$change > $msgfile
-
+if(! ~ $#change 0){
+	edit=1
+	if(test -s .pro/task/$change){
+		if(! ~ $#synopsis 0){
+			echo '#' $synopsis > $msgfile.tmp
+			tail +2 .pro/task/$change >> $msgfile.tmp
+		}
+		if not
+			cat .pro/task/$change > $msgfile.tmp
+	}
+	if not {
+		echo 'no task found for ' $change >[1=2]
+		exit 'missing'
+	}
+}
 
 @{
 	flag e +