|
6 | 6 | import six |
7 | 7 | import sys |
8 | 8 | import vim # pylint: disable=F0401 |
| 9 | +import subprocess |
9 | 10 |
|
10 | 11 | # Insert the taskwiki on the python path |
11 | 12 | BASE_DIR = vim.eval("s:plugin_path") |
@@ -83,6 +84,14 @@ def __init__(self): |
83 | 84 | if not self.tasks: |
84 | 85 | print("No tasks selected.") |
85 | 86 |
|
| 87 | + self.taskopen_notes_folder = ( |
| 88 | + util.get_var("taskwiki_taskopen_notes_folder") or "~/tasknotes" |
| 89 | + ) |
| 90 | + |
| 91 | + self.taskopen_notes_regex = ( |
| 92 | + util.get_var("taskwiki_taskopen_notes_regex") or "Notes" |
| 93 | + ) |
| 94 | + |
86 | 95 | @classmethod |
87 | 96 | def save_action(cls, method, *args): |
88 | 97 | cls.last_action = {'method': method, 'args': args} |
@@ -123,6 +132,34 @@ def info(self): |
123 | 132 | util.show_in_split(out, name='info', activate_cursorline=True) |
124 | 133 | break # Show only one task |
125 | 134 |
|
| 135 | + @errors.pretty_exception_handler |
| 136 | + def open(self): |
| 137 | + compatible_annotation_found = False |
| 138 | + for vimwikitask in self.tasks: |
| 139 | + for annotation in vimwikitask.task["annotations"]: |
| 140 | + annotation = annotation["description"] |
| 141 | + proc = subprocess.Popen(["xdg-open", annotation]) |
| 142 | + try: |
| 143 | + proc.wait(0.3) |
| 144 | + except subprocess.TimeoutExpired: |
| 145 | + compatible_annotation_found = True |
| 146 | + |
| 147 | + if not compatible_annotation_found: |
| 148 | + print("No compatible annotation found.") |
| 149 | + |
| 150 | + @errors.pretty_exception_handler |
| 151 | + def note(self): |
| 152 | + for vimwikitask in self.tasks: |
| 153 | + if self.taskopen_notes_regex not in [ |
| 154 | + a["description"] for a in vimwikitask.task["annotations"] |
| 155 | + ]: |
| 156 | + self.annotate(self.taskopen_notes_regex) |
| 157 | + |
| 158 | + note_path = os.path.join(self.taskopen_notes_folder, |
| 159 | + vimwikitask.task["uuid"] + ".md") |
| 160 | + vim.command("edit " + note_path) |
| 161 | + break # Add not to only one task |
| 162 | + |
126 | 163 | @errors.pretty_exception_handler |
127 | 164 | def edit(self): |
128 | 165 | for vimwikitask in self.tasks: |
|
0 commit comments