]> git.madduck.net Git - etc/taskwarrior.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Add '.config/taskwarrior/hooks/task.shift-recurrence/' from commit 'd06c7ada569cc7566...
authormartin f. krafft <madduck@madduck.net>
Thu, 31 Jan 2019 02:06:20 +0000 (15:06 +1300)
committermartin f. krafft <madduck@madduck.net>
Thu, 31 Jan 2019 02:06:20 +0000 (15:06 +1300)
git-subtree-dir: .config/taskwarrior/hooks/task.shift-recurrence
git-subtree-mainline: 09f6572d50f43509715cd634b47c6e2cd5afe944
git-subtree-split: d06c7ada569cc7566c28dd48f9438849b2a88f8c

.config/taskwarrior/hooks/task.shift-recurrence/.gitignore [new file with mode: 0644]
.config/taskwarrior/hooks/task.shift-recurrence/LICENCE [new file with mode: 0644]
.config/taskwarrior/hooks/task.shift-recurrence/README.md [new file with mode: 0644]
.config/taskwarrior/hooks/task.shift-recurrence/pirate_add_shift_recurrence.py [new file with mode: 0644]

diff --git a/.config/taskwarrior/hooks/task.shift-recurrence/.gitignore b/.config/taskwarrior/hooks/task.shift-recurrence/.gitignore
new file mode 100644 (file)
index 0000000..0d20b64
--- /dev/null
@@ -0,0 +1 @@
+*.pyc
diff --git a/.config/taskwarrior/hooks/task.shift-recurrence/LICENCE b/.config/taskwarrior/hooks/task.shift-recurrence/LICENCE
new file mode 100644 (file)
index 0000000..f90622c
--- /dev/null
@@ -0,0 +1,21 @@
+Copyright 2015 Tomas Babej
+http://github.com/tbabej/taskwarrior-shift-all-recurrence-hook
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/.config/taskwarrior/hooks/task.shift-recurrence/README.md b/.config/taskwarrior/hooks/task.shift-recurrence/README.md
new file mode 100644 (file)
index 0000000..58792c0
--- /dev/null
@@ -0,0 +1,50 @@
+Taskwarrior Shift All Recurrence Attributes Hook
+------------------------------------------------
+
+This is a hook for TaskWarrior (http://www.taskwarrior.org),
+which allow your recurrent tasks to inherit ``wait``, ``scheduled``
+and ``until`` attributes from the parent.
+
+Install
+-------
+
+Note: This hook has been rewritten to leverage taskpirate, for greater hook efficiency.
+Please see https://github.com/tbabej/taskpirate for instructions. Don't worry, it's straightforward.
+
+```
+git clone https://github.com/tbabej/taskwarrior-shift-all-recurrence-hook.git
+cp taskwarrior-shift-all-recurrence-hook/on-* ~/.task/hooks/
+```
+
+This hook leverages tasklib, so you need to install that too:
+
+```
+pip install tasklib
+```
+
+Use case
+--------
+
+Consider you have a periodic task, which is valid only for the certain day,
+e.g. on every Sunday you go running.
+
+```
+$ task add due:sunday recur:weekly
+```
+
+However, TaskWarrior will display the task right away, and you want to
+showing up only during the weekend, so that it does not distract your task
+list during the work week.
+
+If you try to add the recurrence again, this time with ``wait`` attribute,
+to hide the task until it is not relevant for you:
+
+```
+$ task add due:sunday recur:weekly wait:saturday
+```
+
+You will find out that TaskWarrior does not let tasks generated by this
+recurrence inherit the ``wait`` attribute, in the same manner as it does
+with the ``due`` attribute.
+
+This hook solves that.
diff --git a/.config/taskwarrior/hooks/task.shift-recurrence/pirate_add_shift_recurrence.py b/.config/taskwarrior/hooks/task.shift-recurrence/pirate_add_shift_recurrence.py
new file mode 100644 (file)
index 0000000..0266fc5
--- /dev/null
@@ -0,0 +1,29 @@
+#!/usr/bin/python
+
+import sys
+import os
+from tasklib import TaskWarrior
+
+time_attributes = ('wait', 'scheduled')
+
+def is_new_local_recurrence_child_task(task):
+    # Do not affect tasks not spun by recurrence
+    if not task['parent']:
+        return False
+
+    # Newly created recurrence tasks actually have
+    # modified field copied from the parent, thus
+    # older than entry field (until their ID is generated)
+    if (task['modified'] - task['entry']).total_seconds() < 0:
+        return True
+
+tw = TaskWarrior(data_location=os.path.dirname(os.path.dirname(sys.argv[0])))
+tw.overrides.update(dict(recurrence="no", hooks="no"))
+
+def hook_shift_recurrence(task):
+    if is_new_local_recurrence_child_task(task):
+        parent = tw.tasks.get(uuid=task['parent']['uuid'])
+        parent_due_shift = task['due'] - parent['due']
+        for attr in time_attributes:
+            if parent[attr]:
+                task[attr] = parent[attr] + parent_due_shift