task: Add git-sync script hook
Synchronizes a git repository for the taskwarrior data directory, automatically committing any changes after each command; and pushing and pulling on syncing taskwarrior.
This commit is contained in:
parent
b0c5176f1e
commit
a91f553f58
1 changed files with 39 additions and 0 deletions
39
office/.local/share/task/hooks/on-exit.git-sync
Executable file
39
office/.local/share/task/hooks/on-exit.git-sync
Executable file
|
@ -0,0 +1,39 @@
|
|||
#!/bin/sh
|
||||
# Automatically git commits, pushes and pulls if doable in the taskwarrior data directory
|
||||
#
|
||||
# Much of this taken from: https://github.com/mrschyte/taskwarrior-hooks/
|
||||
# with much gratitude
|
||||
|
||||
if [ "${DISABLE_HOOKS}" = "true" ] || ! command -v git >/dev/null 2>&1; then
|
||||
exit 0;
|
||||
fi
|
||||
|
||||
if [ "$1" != "api:2" ]; then
|
||||
printf "Taskwarrior uses different data API version than git plugin. Aborting!" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
data_dir="$(echo "$5" | cut -f2 -d:)"
|
||||
command_run="$(echo "$3" | cut -f2 -d:)"
|
||||
|
||||
# after any command, if there's changes add and commit
|
||||
if ! git -C "$data_dir" diff --exit-code >/dev/null 2>&1; then
|
||||
# need to run to fully update tasks that just got done
|
||||
DISABLE_HOOKS=true env task next >/dev/null 2>&1
|
||||
|
||||
header="auto: ${2##* }"
|
||||
msg="full command: $2"
|
||||
git -C "$data_dir" commit -a -m "$header" -m "$msg" --no-gpg-sign >/dev/null 2>&1
|
||||
fi
|
||||
|
||||
if [ "$command_run" = "synchronize" ]; then
|
||||
DISABLE_HOOKS=true env task sync
|
||||
|
||||
git -C "$data_dir" pull >/dev/null 2>&1
|
||||
pull_ret="$?"
|
||||
git -C "$data_dir" push >/dev/null 2>&1
|
||||
push_ret="$?"
|
||||
if [ "$pull_ret" -eq 0 ] && [ "$push_ret" -eq 0 ]; then
|
||||
echo Git upstream synchronized.
|
||||
fi
|
||||
fi
|
Loading…
Reference in a new issue