Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
These were additions suggested via email. I figured I'd use them first as
- Loading branch information
1 parent
69a15da
commit 23c2c66
Showing
2 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import re, datetime | ||
from todo import usage, iter_todos, CONFIG, concat, _git_commit | ||
from todo import format_lines, PRIORITIES, prioritize_todo, print_x_of_y | ||
|
||
@usage('\tadd | a "Item to do +project @context #{yyyy-mm-dd}"', | ||
concat(["\t\tAdds 'Item to do +project @context #{yyyy-mm-dd}'", | ||
"to your todo.txt"], ' '), "\t\tfile.", | ||
"\t\t+project, @context, #{yyyy-mm-dd} are optional\n") | ||
def add_todo(args): | ||
"""Add a new item to the list of things todo.""" | ||
if str(args) == args: | ||
line = args | ||
elif len(args) >= 1: | ||
line = concat(args, " ") | ||
else: | ||
line = prompt("Add:") | ||
|
||
prepend = CONFIG["PRE_DATE"] | ||
l = len([1 for l in iter_todos()]) + 1 | ||
pri_re = re.compile('(\([A-X]\))') | ||
|
||
if pri_re.match(line) and prepend: | ||
line = pri_re.sub(concat(["\g<1>", | ||
datetime.now().strftime(" %Y-%m-%d ")]), line) | ||
elif prepend: | ||
line = concat([datetime.now().strftime("%Y-%m-%d "), line]) | ||
|
||
with open(CONFIG["TODO_FILE"], "a") as fd: | ||
fd.write(concat([line, "\n"])) | ||
|
||
s = "TODO: '{0}' added on line {1}.".format(line, l) | ||
print(s) | ||
if CONFIG["USE_GIT"]: | ||
_git_commit([CONFIG["TODO_FILE"]], s) | ||
return l | ||
|
||
|
||
@usage('\tsl', "\t\tList items in your todo.txt in reverse priority\n") | ||
def rev_list(): | ||
"""List items in reverse order so for long lists, the most important stuff | ||
won't scroll off the top of the screen.""" | ||
|
||
formatted = format_lines() | ||
lines = [] | ||
for p in PRIORITIES[::-1]: | ||
lines.extend(formatted[p]) | ||
|
||
if lines: | ||
print(concat(lines)[:-1]) | ||
print_x_of_y(lines, lines) | ||
|
||
|
||
@usage('\taddp | ap priority Item to be added', | ||
'\t\tAdds "Item to be added" with priority "priority" to your todo list.\n') | ||
def addp(args): | ||
"""Add an item and then prioritize it.""" | ||
pri = args.pop(0) | ||
prioritize_todo([str(add_todo(args)), pri]) | ||
# If someone did ./todo.py addp c Test addp foo bar bogus the output would be | ||
# TODO: 'Test addp foo bar bogus' added on line 9. | ||
# TODO: Item 9 changed from 'Test addp foo bar bogus' to '(C) Test addp foo bar bogus'. | ||
|
||
commands = { 'addp' : (True, addp), | ||
'ap' : (True, addp), | ||
'sl' : (False, rev_list), | ||
'add' : (True, add), | ||
'a' : (True, add) } |