diff options
| -rwxr-xr-x | .gitignore | 3 | ||||
| -rwxr-xr-x | files/.task/hooks/on-add-default-time.py | 26 | ||||
| -rwxr-xr-x | files/.task/hooks/on-add-spell-check.py | 50 | ||||
| l--------- | files/.task/hooks/on-mod-default-time.py | 1 | ||||
| l--------- | files/.task/hooks/on-mod-spell-check.py | 1 | ||||
| -rw-r--r-- | install.conf.yaml | 1 |
6 files changed, 82 insertions, 0 deletions
@@ -19,3 +19,6 @@ /files/.config/pgcli/* !/files/.config/pgcli/config + +/files/.task/* +!/files/.task/hooks/ 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 diff --git a/install.conf.yaml b/install.conf.yaml index 6b8f167..29316dc 100644 --- a/install.conf.yaml +++ b/install.conf.yaml @@ -14,6 +14,7 @@ ~/.ssh: files/.ssh ~/.lessfilter.sh: files/.lessfilter.sh ~/.psqlrc: files/.psqlrc + ~/.task: files/.task ~/.taskrc: files/.taskrc ~/.vit: files/.vit ~/.reminders: files/.reminders |
