dotfiles/taskwarrior/.local/share/task/hooks/on-exit.sync-to-server-silent.py
Marty Oehme 14896e6292
taskwarrior: Make auto-sync script silent
Now silently syncs in the background instead of blocking input. *May*
produce zombie processes in rare circumstances? Will need to investigate
it some more.

Behind the scenes, the shell script has been replaced by a python script
which creates a (disowned) background process which attempts the
syncing.
2021-07-10 18:04:14 +02:00

29 lines
826 B
Python
Executable file

#!/usr/bin/env python3
# From: https://gist.github.com/varunagrawal/2b93c5dc721520ff6876e940c420ab05
# This hooks script syncs task warrior to the configured task server.
# The on-exit event is triggered once, after all processing is complete.
# Make sure hooks are enabled and this hook script is executable.
# Run `task diag` for diagnostics on the hook.
import sys
import json
import subprocess
try:
tasks = json.loads(sys.stdin.readline())
except:
# No input
sys.exit(0)
# no tasks to work through, don't error
if len(tasks) <= 0:
sys.exit(0)
# Call the `sync` command
# hooks=0 ensures that the sync command doesn't call the on-exit hook
# verbose=nothing sets the verbosity to print nothing at all
subprocess.Popen(["task", "rc.verbose=nothing", "rc.hooks=0", "sync"], close_fds=True)
sys.exit(0)