From 603158c6a7ded34e839353299801ccd34a31a2e0 Mon Sep 17 00:00:00 2001 From: Soispha Date: Tue, 3 Oct 2023 20:21:04 +0200 Subject: fix(hm/conf/taskwarrior/hooks/policies): Also check subprojects --- hm/soispha/conf/taskwarrior/hooks/default.nix | 22 +++++++++++++++++++++- .../hooks/scripts/on-add_enforce-policies.sh | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) (limited to 'hm/soispha/conf/taskwarrior/hooks') diff --git a/hm/soispha/conf/taskwarrior/hooks/default.nix b/hm/soispha/conf/taskwarrior/hooks/default.nix index 66af5b3b..b1b23f3f 100644 --- a/hm/soispha/conf/taskwarrior/hooks/default.nix +++ b/hm/soispha/conf/taskwarrior/hooks/default.nix @@ -1,6 +1,7 @@ { sysLib, pkgs, + lib, ... }: let enforce_policies = sysLib.writeShellScriptWithLibrary { @@ -8,7 +9,26 @@ src = ./scripts/on-add_enforce-policies.sh; dependencies = with pkgs; [dash jq taskwarrior gnused gnugrep]; replacementStrings = let - projects = builtins.map (project: project.name) (import ../projects {}); + mkProject = project: subproject: + if builtins.isString subproject + then { + name = "${project.name}_${subproject}"; + prefix = null; + } + else let + name = builtins.elemAt (builtins.attrNames subproject) 0; + in { + name = "${project.name}_${name}"; + subprojects = builtins.elemAt (builtins.attrValues subproject) 0; + prefix = null; + }; + + mkProjectName = project: + if builtins.hasAttr "subprojects" project + then lib.lists.flatten ([project.name] ++ (builtins.map mkProjectName + (builtins.map (mkProject project) project.subprojects))) + else [project.name]; + projects = lib.lists.flatten (builtins.map mkProjectName (import ../projects {})); projects_newline = builtins.concatStringsSep "\n" projects; projects_comma = builtins.concatStringsSep ", " projects; in { diff --git a/hm/soispha/conf/taskwarrior/hooks/scripts/on-add_enforce-policies.sh b/hm/soispha/conf/taskwarrior/hooks/scripts/on-add_enforce-policies.sh index 84322e6d..1adc4b33 100755 --- a/hm/soispha/conf/taskwarrior/hooks/scripts/on-add_enforce-policies.sh +++ b/hm/soispha/conf/taskwarrior/hooks/scripts/on-add_enforce-policies.sh @@ -22,7 +22,7 @@ enforce_project() { project="$(jq '.project' "$(ptmp "$1")")"; [ "$project" = "null" ] && die "No project supplied!" - if grep -q "^$(echo "$project" | sed 's|"\([a-z0-9_-]*\).*"|\1|')\$" "$(ptmp "%PROJECTS_NEWLINE")"; then + if grep -q "^$(echo "$project" | sed 's|"\(.*\)"|\1|')\$" "$(ptmp "%PROJECTS_NEWLINE")"; then dbg "project('$project') is a valid part of %PROJECTS_COMMA"; else die "The project '$(echo "$project" | sed 's|"||g')' is not registered with the nix config, registered projects: %PROJECTS_COMMA"; -- cgit 1.4.1