Skip to content

Commit 047c417

Browse files
author
patrick.joerg
committed
List all projects
1 parent 643fce4 commit 047c417

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ tn --done => all done issues
3838
tn -p CAD => only open issues from Project CAD
3939
tn --done -c team => only done issues from context team
4040
tn -p CAD -c team => Combinations allowed
41-
tn -l => List all @contexts
41+
tn -l @ => List all @contexts or "+" for projects
4242
```
4343
Project and context can be multiple like -p BIM -p CAD
4444

@@ -64,9 +64,10 @@ Give it the directory to search for and a list of directories to exclude.
6464
- [x] Support - [o] for half done indented lists
6565
- [x] Take the project from the title of the last h1 upwards the file
6666

67-
- [x] Give it some colors and emojis 🤡
68-
- [ ] Make searchpaths a list
67+
- [x] Give it some colors and emojis 🤡
6968
- [x] Give the possibility to exclude subdirectories from search TODO OS "Error 123" on windows
69+
- [x] Give back all projects or contexts like: tn --list -p
70+
- [ ] Make searchpaths a list
7071
- [ ] Add some tests from http://www.nushell.sh/book/testing.html
7172
- [ ] Add a config for depth to show only unindented items per default
7273
- [ ] Group issues by files where they came from
@@ -75,7 +76,6 @@ Give it the directory to search for and a list of directories to exclude.
7576
the file. Then +project should give a combination of the two,
7677
or could even be used for something else.
7778

78-
- [ ] Give back all projects or contexts like: tn --list -p
7979
- [ ] Make a filter for @maybes or configurable words.
8080
- [ ] Create a Link directly to the file and open it in $EDITOR
8181
see otn function, after that

tn.nu

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
6582
def get_list_filter [all: bool, done: bool] {
6683

6784
if ($all and $done) {

0 commit comments

Comments
 (0)