shorter names
This commit is contained in:
parent
7907bee106
commit
1b91006dcf
@ -35,11 +35,19 @@ def get_files(dirname):
|
|||||||
if not dirname:
|
if not dirname:
|
||||||
dirname = "."
|
dirname = "."
|
||||||
else:
|
else:
|
||||||
dirname = dirname[0]
|
dirname = dirname
|
||||||
|
print(dirname)
|
||||||
p = pathlib.Path(dirname).expanduser()
|
p = pathlib.Path(dirname).expanduser()
|
||||||
return p.rglob("*.md")
|
return p.rglob("*.md")
|
||||||
|
|
||||||
|
|
||||||
|
def short_path(f):
|
||||||
|
return str(f).replace(short_path.base_dir, "")
|
||||||
|
|
||||||
|
|
||||||
|
short_path.base_dir = ""
|
||||||
|
|
||||||
|
|
||||||
def lod_table(data: list["TodoItem"]) -> Table | str:
|
def lod_table(data: list["TodoItem"]) -> Table | str:
|
||||||
"""list of dicts to Table"""
|
"""list of dicts to Table"""
|
||||||
if not data:
|
if not data:
|
||||||
@ -78,7 +86,7 @@ def cli():
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TodoItem:
|
class TodoItem:
|
||||||
file: str
|
file: pathlib.Path
|
||||||
status: str
|
status: str
|
||||||
description: str
|
description: str
|
||||||
tags: list[str]
|
tags: list[str]
|
||||||
@ -95,7 +103,7 @@ class TodoItem:
|
|||||||
|
|
||||||
def to_row(self):
|
def to_row(self):
|
||||||
return [
|
return [
|
||||||
self.file,
|
short_path(self.file),
|
||||||
self.status + self.subtask_status(),
|
self.status + self.subtask_status(),
|
||||||
self.description + self.subtask_nested(),
|
self.description + self.subtask_nested(),
|
||||||
" | ".join(self.tags),
|
" | ".join(self.tags),
|
||||||
@ -163,7 +171,7 @@ def pull_todos(file: pathlib.Path):
|
|||||||
elif status == "IDEA":
|
elif status == "IDEA":
|
||||||
style = "blue"
|
style = "blue"
|
||||||
active_todo = TodoItem(
|
active_todo = TodoItem(
|
||||||
file=file.name,
|
file=file,
|
||||||
status=status,
|
status=status,
|
||||||
description=description,
|
description=description,
|
||||||
tags=tag_strs,
|
tags=tag_strs,
|
||||||
@ -213,6 +221,7 @@ def apply_filter(items, rule):
|
|||||||
@click.option("--sort", "-s")
|
@click.option("--sort", "-s")
|
||||||
@click.option("--filter", "-f", multiple=True)
|
@click.option("--filter", "-f", multiple=True)
|
||||||
def todos(dirname, sort, filter):
|
def todos(dirname, sort, filter):
|
||||||
|
short_path.base_dir = dirname
|
||||||
# scan files
|
# scan files
|
||||||
output = [] # list of data
|
output = [] # list of data
|
||||||
for file in get_files(dirname):
|
for file in get_files(dirname):
|
||||||
@ -235,7 +244,7 @@ def todos(dirname, sort, filter):
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class LsItem:
|
class LsItem:
|
||||||
file: str
|
file: pathlib.Path
|
||||||
modified: datetime.datetime
|
modified: datetime.datetime
|
||||||
words: int
|
words: int
|
||||||
todos: int
|
todos: int
|
||||||
@ -251,7 +260,7 @@ class LsItem:
|
|||||||
|
|
||||||
def to_row(self):
|
def to_row(self):
|
||||||
return [
|
return [
|
||||||
self.file,
|
short_path(self.file),
|
||||||
human_readable_date(self.modified),
|
human_readable_date(self.modified),
|
||||||
str(self.words),
|
str(self.words),
|
||||||
str(self.todos),
|
str(self.todos),
|
||||||
@ -295,6 +304,7 @@ def scan_contents(file: pathlib.Path) -> dict:
|
|||||||
@click.argument("dirname", default="")
|
@click.argument("dirname", default="")
|
||||||
@click.option("--sort", "-s")
|
@click.option("--sort", "-s")
|
||||||
def ls(dirname, sort):
|
def ls(dirname, sort):
|
||||||
|
short_path.base_dir = dirname
|
||||||
# scan files
|
# scan files
|
||||||
output = []
|
output = []
|
||||||
for file in get_files(dirname):
|
for file in get_files(dirname):
|
||||||
@ -303,7 +313,7 @@ def ls(dirname, sort):
|
|||||||
scan = scan_contents(file)
|
scan = scan_contents(file)
|
||||||
output.append(
|
output.append(
|
||||||
LsItem(
|
LsItem(
|
||||||
file=file.name,
|
file=file,
|
||||||
modified=modified,
|
modified=modified,
|
||||||
style="yellow" if scan["todos"] else "white",
|
style="yellow" if scan["todos"] else "white",
|
||||||
**scan,
|
**scan,
|
||||||
|
Loading…
Reference in New Issue
Block a user