Skip to content

Commit ba600ab

Browse files
authored
add extract-todos v1.0 (#233)
1 parent f1604c9 commit ba600ab

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

extract-todos/extract-todos.qml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import QtQml 2.0
2+
import QOwnNotesTypes 1.0
3+
4+
Script {
5+
property string subFolder;
6+
property variant settingsVariables: [
7+
{
8+
"identifier": "subFolder",
9+
"name": "TODO Subfolder",
10+
"description": "Restrict search for TODOs to this note subfolder.",
11+
"type": "string",
12+
"default": "",
13+
}
14+
];
15+
16+
function init() {
17+
script.registerLabel("extract todos")
18+
extractTodos()
19+
}
20+
21+
function extractTodos() {
22+
23+
const path = script.currentNoteFolderPath() + "/" + subFolder;
24+
const findResult = script.startSynchronousProcess("find", ["\(", "-name", "*.md", "-or", "-name", "*.txt", "\)", "-printf", "%P\n"], "", path);
25+
const files = findResult.toString().split("\n");
26+
27+
const todoRegex = /^\s*- \[ \]\s*/;
28+
var output = "<h1>Open TODOs</h1>\n";
29+
30+
for (const i in files) {
31+
const file = files[i];
32+
const text = script.startSynchronousProcess("cat", [ file ], "", path);
33+
const todos = text.toString()
34+
.split("\n")
35+
.filter(s => s.match(todoRegex))
36+
.map(s => s.replace(todoRegex, ""));
37+
if (todos.length > 0) {
38+
output += "<h3>" + file + "</h3><ul>\n";
39+
for (const j in todos) {
40+
output += "<p>" + todos[j] + "</p>\n";
41+
}
42+
output += "</ul>\n";
43+
}
44+
}
45+
46+
script.setLabelText("extract todos", output);
47+
}
48+
49+
function onNoteStored(note) { extractTodos() }
50+
}
51+

extract-todos/info.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "Extract TODOs",
3+
"identifier": "extract-todos",
4+
"script": "extract-todos.qml",
5+
"authors": ["@jaschop-1k5o"],
6+
"platforms": ["linux"],
7+
"version": "1.0",
8+
"minAppVersion": "24.5.1",
9+
"description" : "Continuously scan your note folder for open TODOs, and display them in the scripting panel.\n\nTODOs are identified according to Markdown syntax, by lines starting with `- [ ]`\nScanning can be restricted to a subfolder.\n(Note: Script uses `find` and `grep` in the background.)"
10+
}
11+

0 commit comments

Comments
 (0)