Example #1
0
 def add_related_todo(self, t, rest):
     todostr = t.get_string_excluding(['text', 'cdstr', 'donestr'])
     text = " {}".format(rest)
     newval = self.edit_todo_string(todostr + text)
     newtodo = todo_from_line(newval)
     self.current_file.add_todo(newtodo)
     self.dirty = True
Example #2
0
 def do_edit(self, rest):
     "Edit the current todo"
     newval = self.edit_todo_string(str(self.current_todo))
     if newval != str(self.current_todo):
         self.dirty = True
         newtodo = todo_from_line(newval)
         self.current_file.replace_todo(self.current_todo,
                                        newtodo)
         self.current_todos[self.current_todo_index] = newtodo
     self.show_next()
Example #3
0
    def do_new(self, rest):
        "Add new todo to file (or file prefix) given as first arg."
        if len(rest.split(' ', 1)) == 1:
            print("usage: new <fileprefix> <todotxt>")
            return
        fileprefix, todotxt = rest.split(' ', 1)
        matching_filenames = [fn for fn in self.all_files.keys()
                              if fn.startswith(fileprefix)]
        if len(matching_filenames) == 0:
            print("no files match '{}'".format(fileprefix))
            return
        elif len(matching_filenames) > 1:
            print("too many matches for '{}' - "
                  "add characters".format(fileprefix))
            return

        f = self.all_files[matching_filenames[0]]
        t = todo_from_line(todotxt)
        t.set_created_now()
        f.add_todo(t)
        self.refresh_current_todos()
Example #4
0
def do_edit(todo, f):
    "Edit the todo"
    def hook():
        readline.insert_text(str(todo))
    readline.set_startup_hook(hook)
    old_delims = readline.get_completer_delims()
    new_delims = old_delims.replace('@', '')
    new_delims = new_delims.replace('+', '')
    new_delims = new_delims.replace('#', '')
    readline.set_completer_delims(new_delims)
    readline.set_completer(completer)
    newval = input("editing: ")
    readline.set_startup_hook(None)
    readline.set_completer(None)
    readline.set_completer_delims(old_delims)
    if newval != str(todo):
        newtodo = todo_from_line(newval)
        f.replace_todo(todo,
                       newtodo)
        f.save()
        print("Saved :'{}'".format(str(newtodo)))
Example #5
0
from todotxt import TODOFile, DATE_FMT, todo_from_line

if __name__ == "__main__":
    # todo.sh usage:
    if len(sys.argv) > 1 and sys.argv[1] == "usage":
        print("USAGE: ...")
        sys.exit()

    parser = argparse.ArgumentParser(description="todotxt 'ADD' script")
    parser.add_argument("--dir", default=os.environ.get("TODO_DIR", "."), help="Directory to look for todo.txt files")
    parser.add_argument("-f", dest="fnpat", default="todo.txt", help="filename prefix to save to")
    parser.add_argument("text", nargs=argparse.REMAINDER, help="text of new todo")

    opts = parser.parse_args()

    if opts.fnpat.endswith(".txt"):
        wildcard = ""
    else:
        wildcard = "*.txt"
    fnl = glob(os.path.join(opts.dir, "{}{}".format(opts.fnpat, wildcard)))
    if len(fnl) > 1:
        print("Too many matches for -f: {}".format(", ".join(fnl)))
        sys.exit(1)

    todo_file = TODOFile(fnl[0])

    t = todo_from_line(" ".join(opts.text))
    t.set_created_now()
    todo_file.add_todo(t)
    todo_file.save()