Repository navigation
Expand file tree
/
Copy pathmits.py
More file actions
236 lines (190 loc) · 7.51 KB
/
Copy pathmits.py
File metadata and controls
236 lines (190 loc) · 7.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/usr/bin/env python3
"""
MITs — terminal task manager enforcing the 3 Most Important Tasks method.
CLIG-compliant CLI. See https://clig.dev/
"""
from __future__ import annotations
import argparse
import signal
import sys
# ── Ctrl+C — clean exit, no traceback ────────────────────────────────────────
def _handle_sigint(_sig, _frame) -> None:
print(file=sys.stderr)
sys.exit(0)
signal.signal(signal.SIGINT, _handle_sigint)
# ── Argument parser ───────────────────────────────────────────────────────────
def build_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
prog="mits",
description="Terminal task manager — 3 Most Important Tasks per day.",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""\
examples:
mits launch the TUI
mits "fix the bug" add to inbox
mits today "fix the bug" add to today
mits today "fix +work" add to today, tag project #work
mits inbox "idea +gcmedia" add to inbox with project tag
mits --summary print today's MITs and exit
mits --summary --json machine-readable summary (pipe to jq)
mits --report print weekly markdown report
mits --report > week.md save report to file
inline task syntax (works in TUI add/edit prompts too):
"today: title +project due:fri recur:daily ★"
due values: today, tomorrow, mon-sun, +3 (days), 2026-04-10
recur values: daily, weekly, weekdays
list prefix: today: / inbox: / someday: (at start or after title tokens)
environment variables:
MITS_DATA override data file path (legacy: MIT_DATA)
MITS_MIT_LIMIT override MIT limit (default: 3; legacy: MIT_MIT_LIMIT)
NO_COLOR disable color output (https://no-color.org/)
paths:
data: $XDG_DATA_HOME/mits/data.json (~/.local/share/mits/data.json)
config: $XDG_CONFIG_HOME/mits/config.json (~/.config/mits/config.json)
shell greeting — add to .zshrc / .bashrc:
python /path/to/mits.py --summary
feedback & issues: https://github.com/lahbibsemlali/mit
""",
)
parser.add_argument(
"list_or_title",
nargs="?",
metavar="LIST|TITLE",
help="list name (today/inbox/someday) or task title to add to inbox",
)
parser.add_argument(
"title",
nargs="?",
metavar="TITLE",
help="task title (when first arg is a list name)",
)
parser.add_argument(
"--summary",
action="store_true",
help="print today's MITs and stats, then exit (use in .zshrc)",
)
parser.add_argument(
"--report",
action="store_true",
help="print weekly markdown report to stdout",
)
parser.add_argument(
"--json",
action="store_true",
help="output --summary in JSON format (machine-readable)",
)
parser.add_argument(
"--version",
action="version",
version="mits 0.1.0",
)
return parser
# ── CLI commands ──────────────────────────────────────────────────────────────
def cmd_summary(json_mode: bool = False) -> None:
from data import load_data, generate_summary, generate_summary_json
data = load_data()
if json_mode:
print(generate_summary_json(data))
else:
from rich.console import Console
from logo import print_logo
c = Console()
print_logo(c)
c.print(generate_summary(data))
sys.exit(0)
def cmd_report() -> None:
from data import load_data, generate_report
data = load_data()
print(generate_report(data))
sys.exit(0)
def cmd_add(list_or_title: str, extra_title: str | None) -> None:
from data import (
load_data, save_data, make_task,
parse_quick_input, suggest_list, VALID_LISTS,
)
low = list_or_title.lower()
if low in VALID_LISTS and extra_title:
lst = low
final_title = extra_title
elif low in VALID_LISTS and not extra_title:
print(f"mits: error: list '{low}' given but no task title", file=sys.stderr)
print(f'usage: mits {low} "task title"', file=sys.stderr)
sys.exit(2)
elif extra_title is not None:
# Two args but first is not a valid list — typo?
suggestion = suggest_list(list_or_title)
print(f"mits: '{list_or_title}' is not a valid list.", file=sys.stderr)
if suggestion:
print(f"did you mean '{suggestion}'?", file=sys.stderr)
print(f' mits {suggestion} "{extra_title}"', file=sys.stderr)
else:
print("valid lists: today, inbox, someday", file=sys.stderr)
sys.exit(2)
else:
# Single arg — treat as task title, add to inbox
lst = "inbox"
final_title = list_or_title
# Use the unified parser
result = parse_quick_input(final_title, default_list=lst)
data = load_data()
project_name = result.get("project", "")
if project_name:
projects = data.setdefault("projects", [])
if project_name not in projects:
if sys.stdin.isatty():
try:
ans = input(
f"mits: project '+{project_name}' is not in your list. Create it? [Y/n] "
).strip().lower()
except EOFError:
ans = "y"
if ans in ("", "y", "yes"):
projects.append(project_name)
else:
project_name = ""
result["project"] = ""
else:
print(
f"mits: creating new project '+{project_name}' (non-interactive)",
file=sys.stderr,
)
projects.append(project_name)
# Enforce MIT limits
if result.get("is_mit"):
active_mits = sum(1 for t in data.get("tasks", []) if t.get("is_mit") and not t.get("done"))
from data import MIT_LIMIT
if active_mits >= MIT_LIMIT:
result["is_mit"] = False
print(f"mits: limit of {MIT_LIMIT} MITs reached — task added without ★", file=sys.stderr)
task = make_task(
result["title"],
result["list"],
project_name,
result.get("due"),
result.get("recur"),
)
task["is_mit"] = result.get("is_mit", False)
data["tasks"].append(task)
save_data(data)
proj_tag = f" +{project_name}" if project_name else ""
print(f"⚡ added to {result['list']}: {result['title']}{proj_tag}")
sys.exit(0)
# ── Entry point ───────────────────────────────────────────────────────────────
def main() -> None:
parser = build_parser()
args = parser.parse_args()
if args.summary:
cmd_summary(json_mode=args.json)
elif args.report:
cmd_report()
elif args.list_or_title:
cmd_add(args.list_or_title, args.title)
else:
# Launch TUI only when stdin is an interactive terminal
if not sys.stdin.isatty():
parser.print_help(sys.stderr)
sys.exit(1)
from app import ForgeApp
ForgeApp().run()
if __name__ == "__main__":
main()