This commit is contained in:
James Turk 2024-07-27 15:07:22 -04:00
parent 615a0c9254
commit 279b45b1ee
4 changed files with 34 additions and 11 deletions

View File

@ -1,11 +1,12 @@
# maddog # modo
A suite of tools for dealing with a directory of markdown files. A suite of tools for dealing with a directory of markdown files.
## Tasks ## Tasks
- TODO: improve inline help
- TODO: more flags - TODO: more flags
- [ ] filters - [x] filters
- [x] sorting - [x] sorting
- [ ] reverse sort - [ ] reverse sort
- TODO: add config file {by:2024-08-01} - TODO: add config file {by:2024-08-01}
@ -14,7 +15,7 @@ A suite of tools for dealing with a directory of markdown files.
- DONE: support checkboxes - DONE: support checkboxes
- [x] scan lists - [x] scan lists
- [x] percent complete - [x] percent complete
- TODO: decide on more permanent name {by:2024-08-15} - DONE: decide on more permanent name {by:2024-08-15}
- IDEA: recurring? - IDEA: recurring?
- IDEA: track changes - IDEA: track changes
- DONE: add color {by: 2024-07-26} - DONE: add color {by: 2024-07-26}

View File

@ -1,7 +1,7 @@
[project] [project]
name = "maddog" name = "modo"
version = "0.1.0" version = "0.1.0"
description = "markdown tools" description = "todos and more from simple markdown"
authors = [{ name = "James Turk", email = "dev@jpt.sh" }] authors = [{ name = "James Turk", email = "dev@jpt.sh" }]
dependencies = ["click>=8.1.7", "rich>=13.7.1", "python-dateutil>=2.9.0.post0"] dependencies = ["click>=8.1.7", "rich>=13.7.1", "python-dateutil>=2.9.0.post0"]
requires-python = ">=3.12" requires-python = ">=3.12"
@ -9,7 +9,7 @@ readme = "README.md"
license = { text = "MIT" } license = { text = "MIT" }
[project.scripts] [project.scripts]
maddog = "maddog.app:cli" modo = "modo.app:cli"
[build-system] [build-system]
requires = ["pdm-backend"] requires = ["pdm-backend"]

View File

@ -187,19 +187,37 @@ def get_todo_sort_func(keys):
return sort_func return sort_func
def apply_filter(items, rule):
key, val = rule.split(":")
if key == "status":
return [item for item in items if item.status == val]
else:
return [item for item in items if rule in item.tags]
@cli.command() @cli.command()
@click.argument("dirname", nargs=-1) @click.argument("dirname", default="")
@click.option("--sort", "-s") @click.option("--sort", "-s")
def todos(dirname, sort): @click.option("--filter", "-f", multiple=True)
def todos(dirname, sort, filter):
# scan files
output = [] # list of data output = [] # list of data
for file in get_files(dirname): for file in get_files(dirname):
output += pull_todos(file) output += pull_todos(file)
# filter
for rule in filter:
output = apply_filter(output, rule)
# do sorting
if not sort: if not sort:
sort = ["status", "due"] sort = ["status", "due"]
else: else:
sort = sort.split(",") sort = sort.split(",")
sort_func = get_todo_sort_func(sort) sort_func = get_todo_sort_func(sort)
output.sort(key=sort_func) output.sort(key=sort_func)
# display
table = lod_table(output) table = lod_table(output)
console.print(table) console.print(table)
@ -256,7 +274,7 @@ def human_readable_date(dt: datetime.datetime) -> str:
elif delta < datetime.timedelta(days=1): elif delta < datetime.timedelta(days=1):
return f"{int(delta.total_seconds() / 3600)}h ago" return f"{int(delta.total_seconds() / 3600)}h ago"
else: else:
return f"{int(delta.total_seconds() / 3600 / 24)}d ago" return f"{delta.days}d ago"
def scan_contents(file: pathlib.Path) -> dict: def scan_contents(file: pathlib.Path) -> dict:
@ -266,10 +284,10 @@ def scan_contents(file: pathlib.Path) -> dict:
@cli.command() @cli.command()
@click.argument("dirname", nargs=-1) @click.argument("dirname", default="")
@click.option("--sort", "-s") @click.option("--sort", "-s")
def ls(dirname, sort): def ls(dirname, sort):
table = Table() # scan files
output = [] output = []
for file in get_files(dirname): for file in get_files(dirname):
st = file.stat() st = file.stat()
@ -283,12 +301,16 @@ def ls(dirname, sort):
**scan, **scan,
) )
) )
# sort
if not sort: if not sort:
sort = ["file", "modified"] sort = ["file", "modified"]
else: else:
sort = sort.split(",") sort = sort.split(",")
sort_func = get_ls_sort_func(sort) sort_func = get_ls_sort_func(sort)
output.sort(key=sort_func) output.sort(key=sort_func)
# display
table = lod_table(output) table = lod_table(output)
console.print(table) console.print(table)