From: martin f. krafft Date: Thu, 31 Jan 2019 02:06:20 +0000 (+1300) Subject: Add '.config/taskwarrior/hooks/task.shift-recurrence/' from commit 'd06c7ada569cc7566... X-Git-Url: https://git.madduck.net/etc/taskwarrior.git/commitdiff_plain/a8767d0e7ed2339be98c6244ead25d63034f85b9?hp=-c Add '.config/taskwarrior/hooks/task.shift-recurrence/' from commit 'd06c7ada569cc7566c28dd48f9438849b2a88f8c' git-subtree-dir: .config/taskwarrior/hooks/task.shift-recurrence git-subtree-mainline: 09f6572d50f43509715cd634b47c6e2cd5afe944 git-subtree-split: d06c7ada569cc7566c28dd48f9438849b2a88f8c --- a8767d0e7ed2339be98c6244ead25d63034f85b9 diff --combined .config/taskwarrior/hooks/task.shift-recurrence/.gitignore index 0000000,0d20b64..0d20b64 mode 000000,100644..100644 --- a/.config/taskwarrior/hooks/task.shift-recurrence/.gitignore +++ b/.config/taskwarrior/hooks/task.shift-recurrence/.gitignore @@@ -1,0 -1,1 +1,1 @@@ + *.pyc diff --combined .config/taskwarrior/hooks/task.shift-recurrence/LICENCE index 0000000,f90622c..f90622c mode 000000,100644..100644 --- a/.config/taskwarrior/hooks/task.shift-recurrence/LICENCE +++ b/.config/taskwarrior/hooks/task.shift-recurrence/LICENCE @@@ -1,0 -1,21 +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 --combined .config/taskwarrior/hooks/task.shift-recurrence/README.md index 0000000,58792c0..58792c0 mode 000000,100644..100644 --- a/.config/taskwarrior/hooks/task.shift-recurrence/README.md +++ b/.config/taskwarrior/hooks/task.shift-recurrence/README.md @@@ -1,0 -1,50 +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 --combined .config/taskwarrior/hooks/task.shift-recurrence/pirate_add_shift_recurrence.py index 0000000,0266fc5..0266fc5 mode 000000,100644..100644 --- a/.config/taskwarrior/hooks/task.shift-recurrence/pirate_add_shift_recurrence.py +++ b/.config/taskwarrior/hooks/task.shift-recurrence/pirate_add_shift_recurrence.py @@@ -1,0 -1,29 +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