aboutsummaryrefslogtreecommitdiff
path: root/files/.task
diff options
context:
space:
mode:
authorAnton Bobov <abobov@gmail.com>2020-09-15 20:16:11 +0500
committerAnton Bobov <abobov@gmail.com>2020-09-15 22:12:32 +0500
commit58200984aa4dff48d7925f48e443a00775c0ba07 (patch)
treee7495de25e0b243dd617621a409bacfb17178b55 /files/.task
parent9d9c0fe43a2f0010ac3dbc66f42ebe91ab7e275c (diff)
Add taskwarrior hooks.
Diffstat (limited to 'files/.task')
-rwxr-xr-xfiles/.task/hooks/on-add-default-time.py26
-rwxr-xr-xfiles/.task/hooks/on-add-spell-check.py50
l---------files/.task/hooks/on-mod-default-time.py1
l---------files/.task/hooks/on-mod-spell-check.py1
4 files changed, 78 insertions, 0 deletions
diff --git a/files/.task/hooks/on-add-default-time.py b/files/.task/hooks/on-add-default-time.py
new file mode 100755
index 0000000..ec2cc41
--- /dev/null
+++ b/files/.task/hooks/on-add-default-time.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python3
+# Adopted from https://github.com/tbabej/task.default-date-time
+from datetime import time
+from tasklib import Task, local_zone
+
+
+DEFAULT_TIME = time(22, 0, 0)
+
+
+def is_local_midnight(timestamp):
+ return timestamp.astimezone(local_zone).time() == time(0, 0, 0)
+
+def set_default_time(timestamp):
+ return timestamp.astimezone(local_zone).replace(
+ hour=DEFAULT_TIME.hour,
+ minute=DEFAULT_TIME.minute,
+ second=DEFAULT_TIME.second
+ )
+
+
+task = Task.from_input()
+if task['due'] and is_local_midnight(task['due']):
+ task['due'] = set_default_time(task['due'])
+ print("Default due time has been set.")
+
+print(task.export_data())
diff --git a/files/.task/hooks/on-add-spell-check.py b/files/.task/hooks/on-add-spell-check.py
new file mode 100755
index 0000000..16758f0
--- /dev/null
+++ b/files/.task/hooks/on-add-spell-check.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python3
+from glob import glob
+from os.path import isfile, splitext
+import os
+import re
+import sys
+
+try:
+ from hunspell import HunSpell
+ from tasklib import Task, local_zone
+except ImportError as e:
+ print(e)
+ sys.exit(0)
+
+
+DICT_PATH = '/usr/share/hunspell/'
+LANGS = ['en_US', 'ru_RU']
+ENV_SKIP = 'TW_IGNORE_SPELL'
+
+
+def spellcheck(text):
+ spells = []
+ for dic in glob(DICT_PATH + '*.dic'):
+ aff = splitext(dic)[0] + '.aff'
+ if isfile(dic) and isfile(aff):
+ spells.append(HunSpell(dic, aff))
+
+ if len(spells) == 0:
+ return
+
+ errors = []
+
+ for word in re.findall(r'\w+', text):
+ ok = False
+ for spell in spells:
+ if spell.spell(word):
+ ok = True
+ break
+ if not ok:
+ errors.append(word)
+
+ return errors
+
+task = Task.from_input()
+errors = spellcheck(task['description'])
+if len(errors) > 0:
+ print('Spell errors:', ', '.join(errors))
+ if not ENV_SKIP in os.environ:
+ sys.exit(1)
+print(task.export_data())
diff --git a/files/.task/hooks/on-mod-default-time.py b/files/.task/hooks/on-mod-default-time.py
new file mode 120000
index 0000000..fa7f03a
--- /dev/null
+++ b/files/.task/hooks/on-mod-default-time.py
@@ -0,0 +1 @@
+on-add-default-time.py \ No newline at end of file
diff --git a/files/.task/hooks/on-mod-spell-check.py b/files/.task/hooks/on-mod-spell-check.py
new file mode 120000
index 0000000..e632b33
--- /dev/null
+++ b/files/.task/hooks/on-mod-spell-check.py
@@ -0,0 +1 @@
+on-add-spell-check.py \ No newline at end of file