summary refs log tree commit diff
path: root/dot_local/bin/executable_todosort.py
diff options
context:
space:
mode:
Diffstat (limited to 'dot_local/bin/executable_todosort.py')
-rw-r--r--dot_local/bin/executable_todosort.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/dot_local/bin/executable_todosort.py b/dot_local/bin/executable_todosort.py
new file mode 100644
index 0000000..2f75ee9
--- /dev/null
+++ b/dot_local/bin/executable_todosort.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main() -> None:
+    priority_words = {w.lower() for w in sys.argv[1:]}
+    lines = []
+    for line in sys.stdin.readlines():
+        words = line.split()
+        if words[1].startswith('(') and words[1].endswith(')'):
+            priority = words[1]
+        else:
+            priority = '(X)'
+        for due in words:
+            if due.startswith('due:'):
+                break
+        else:
+            due = 'due:3000-01-01'
+        has_priority_words = not any(w.lstrip('+#@').lower() in priority_words for w in words)
+        lines.append((priority, has_priority_words, due, line))
+    print(''.join(l for *_, l in sorted(lines)))
+
+
+if __name__ == '__main__':
+    main()