@@ -6,11 +6,12 @@ export def td [
66 -- project(-p) : string = " " # All todos within a +project
77 -- context(-c) : string = " " # All todos within a @context
88 -- retro(-r) : string = " " # A retrospective for todos in git history
9- -- list(-l) # List all @contexts used
9+ -- list(-l): string = " " # List all @contexts or +projects used.
1010 -- version(-v) # Version of todo-nu
1111 ] {
1212
13- let generate_todos = (($retro | is-empty ) and ($list == false ))
13+ let generate_todos = (($retro | is-empty ) and ($list | is-empty ))
14+ echo $list
1415 let list_contexts = ($retro | is-empty )
1516
1617 # The path to parse
@@ -21,15 +22,21 @@ export def td [
2122 let EXCLUDEDIR = $CONFIG.exclude
2223
2324 if $version {
24- let version = " 0.0.3 "
25+ let version = " 0.0.4 "
2526 $version
2627 } else if $generate_todos {
2728 let td = generate_todos $TODO_FILE_PATH $EXCLUDEDIR $FILTER $project $context
2829 $td
2930 } else if $list_contexts {
30- let td = generate_todos $TODO_FILE_PATH $EXCLUDEDIR $FILTER $project $context
31- let l = list_contexts $td
32- $l
31+ if $list == " @" {
32+ let td = generate_todos $TODO_FILE_PATH $EXCLUDEDIR $FILTER $project $context
33+ let l = list_contexts $td
34+ $l
35+ } else if $list == " +" {
36+ let td = generate_todos $TODO_FILE_PATH $EXCLUDEDIR $FILTER $project $context
37+ let l = list_projects $td
38+ $l
39+ } else {" Either specify " @ " for contexts or " + " for projects" }
3340 } else {
3441 let r = (get_retrospective $retro $TODO_FILE_PATH $FILTER )
3542 $r
@@ -43,7 +50,6 @@ def generate_todos [todo_file_path: path,
4350 context : string ] {
4451 let excludes = (generate_excludes_list $todo_file_path $excludedir )
4552 let todos = (filter_todos $todo_file_path $filter $excludes )
46- # let filtered = (filter_excludes $todos $EXCLUDEDIR)
4753 # Filter by project and context
4854 let tn = (get_project_context_filter $todos $project $context )
4955 # Parse it to a table
@@ -62,6 +68,17 @@ def list_contexts [todos: table] {
6268 $contexts | uniq -- count | compact | filter {|x | $x.value != " " }
6369}
6470
71+ # Get a list of all +projects beeing used. Although a project should actually be a file.
72+ # One approach could be to count both the appearences of "+" and the same word as filename
73+ #Not of much need for now.
74+ def list_projects [todos : table ] {
75+ # Get all strings with the pattern "+something", but not if its a code in backticks
76+ # Doesn't catch multiline code blocks containing this pattern inside.
77+ let projects = ($todos | get item | each {|e | parse -- regex ' (`[^`]*`)|\+([^\s]+)' |
78+ get capture1 | flatten }) | flatten
79+ $projects | uniq -- count | compact | filter {|x | $x.value != " " }
80+ }
81+
6582def get_list_filter [all : bool , done : bool ] {
6683
6784 if ($all and $done ) {
0 commit comments