Skip to content

Instantly share code, notes, and snippets.

@danmou
Forked from varunagrawal/on-exit-sync.py
Last active November 26, 2018 12:35
Show Gist options
  • Save danmou/83079feac22307813178d7f8c456c544 to your computer and use it in GitHub Desktop.
Save danmou/83079feac22307813178d7f8c456c544 to your computer and use it in GitHub Desktop.
Script to sync Taskwarrior after each operation
#!/usr/bin/env python3
# This hooks script syncs task warrior to the configured task server without blocking.
# 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
pass
# 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.hooks=0", "rc.verbose=nothing", "sync"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, stdin=subprocess.PIPE)
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment