diff options
Diffstat (limited to '')
4 files changed, 110 insertions, 7 deletions
diff --git a/hm/soispha/conf/taskwarrior/default.nix b/hm/soispha/conf/taskwarrior/default.nix index 53a548ad..b3ce3933 100644 --- a/hm/soispha/conf/taskwarrior/default.nix +++ b/hm/soispha/conf/taskwarrior/default.nix @@ -1,6 +1,7 @@ { nixosConfig, lib, + config, ... }: { imports = [ @@ -91,6 +92,8 @@ }; color = true; + hooks.location="${config.xdg.configHome}/task/hooks"; + urgency.uda.priority = { H.coefficient = 6.0; M.coefficient = 0; diff --git a/hm/soispha/conf/taskwarrior/hooks/default.nix b/hm/soispha/conf/taskwarrior/hooks/default.nix index 208397bc..31d97529 100644 --- a/hm/soispha/conf/taskwarrior/hooks/default.nix +++ b/hm/soispha/conf/taskwarrior/hooks/default.nix @@ -2,10 +2,11 @@ sysLib, pkgs, lib, + config, ... }: let enforce_policies = sysLib.writeShellScriptWithLibrary { - name = "enforce_policies.taskwarrior-hook"; + name = "bin"; src = ./scripts/on-add_enforce-policies.sh; dependencies = with pkgs; [dash jq taskwarrior gnused gnugrep]; replacementStrings = let @@ -63,12 +64,24 @@ dontUnpack = true; installPhase = "install -Dm755 ${./scripts/on-modify_track-total-active-time.py} $out/bin/bin"; }; -in { - xdg = { - dataFile = { - "task/hooks/on-add_enforce-policies".source = "${enforce_policies}/bin/enforce_policies.taskwarrior-hook"; - "task/hooks/on-modify_track-timewarrior".source = "${track_timewarrior}/bin/bin"; - "task/hooks/on-modify_track-total-active-time".source = "${track_total_active_time}/bin/bin"; + + mkSyncGitRepo = type: { + name = "${hookPath}/${type}_sync-git-repo"; + value = { + source = "${sysLib.writeShellScriptWithLibrary { + name = "bin"; + src = ./scripts + "/${type}_sync-git-repo.sh"; + dependencies = with pkgs; [dash taskwarrior git]; + }}/bin/bin"; }; }; + sync_git_repos = + builtins.listToAttrs (builtins.map mkSyncGitRepo ["on-add" "on-modify"]); + hookPath = config.programs.taskwarrior.config.hooks.location; +in { + home.file = { + "${hookPath}/on-add_enforce-policies".source = "${enforce_policies}/bin/bin"; + "${hookPath}/on-modify_track-timewarrior".source = "${track_timewarrior}/bin/bin"; + "${hookPath}/on-modify_track-total-active-time".source = "${track_total_active_time}/bin/bin"; + } // sync_git_repos; } diff --git a/hm/soispha/conf/taskwarrior/hooks/scripts/on-add_sync-git-repo.sh b/hm/soispha/conf/taskwarrior/hooks/scripts/on-add_sync-git-repo.sh new file mode 100755 index 00000000..b2e65c1d --- /dev/null +++ b/hm/soispha/conf/taskwarrior/hooks/scripts/on-add_sync-git-repo.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="1.4.2" . %SHELL_LIBRARY_PATH + +# override shell lib output to stdout +eprint() { + # shellcheck disable=SC2317 + print "$@"; +}; +eprintln() { + # shellcheck disable=SC2317 + println "$@"; +}; + +enable_hook_dbg() { + debug_hooks="$(task _get rc.debug.hooks)"; + [ "$debug_hooks" ] && [ "$debug_hooks" -ge 1 ] && dbg_enable +} + +update_git_repo() { + task_data="$(task _get rc.data.location)"; + [ "$task_data" ] || die "Taskwarrior should have a location set" + + cd "$task_data" || die "(BUG?): Your data.location path is not accessable" + + [ -d ./.git/ ] || git init + + git add .; + git commit --message="chore: Update" --no-gpg-sign; +} + + +read -r new_task; +# We don't change the task, thus immediately return the json +echo "$new_task"; + +enable_hook_dbg; +update_git_repo; + +exit 0; + +# vim: ft=sh diff --git a/hm/soispha/conf/taskwarrior/hooks/scripts/on-modify_sync-git-repo.sh b/hm/soispha/conf/taskwarrior/hooks/scripts/on-modify_sync-git-repo.sh new file mode 100755 index 00000000..e2c0abcb --- /dev/null +++ b/hm/soispha/conf/taskwarrior/hooks/scripts/on-modify_sync-git-repo.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env dash + +# shellcheck source=/dev/null +SHELL_LIBRARY_VERSION="1.4.2" . %SHELL_LIBRARY_PATH + +# override shell lib output to stdout +eprint() { + # shellcheck disable=SC2317 + print "$@"; +}; +eprintln() { + # shellcheck disable=SC2317 + println "$@"; +}; + +enable_hook_dbg() { + debug_hooks="$(task _get rc.debug.hooks)"; + [ "$debug_hooks" ] && [ "$debug_hooks" -ge 1 ] && dbg_enable +} + +update_git_repo() { + task_data="$(task _get rc.data.location)"; + [ "$task_data" ] || die "Taskwarrior should have a location set" + + cd "$task_data" || die "(BUG?): Your data.location path is not accessable" + + [ -d ./.git/ ] || git init + + git add .; + git commit --message="chore: Update" --no-gpg-sign; +} + + +read -r _old_task; +read -r new_task; +# We don't change the task, thus immediately return the json +echo "$new_task"; + +enable_hook_dbg; +update_git_repo; + +exit 0; + +# vim: ft=sh |