pay-respects: add rules support
Allow creating rules files now following docs from https://github.com/iffse/pay-respects/blob/main/rules.md Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
This commit is contained in:
parent
9bdb693810
commit
133585ddfa
1 changed files with 51 additions and 0 deletions
|
|
@ -8,6 +8,7 @@ let
|
|||
cfg = config.programs.pay-respects;
|
||||
payRespectsCmd = lib.getExe cfg.package;
|
||||
cfgOptions = lib.concatStringsSep " " cfg.options;
|
||||
tomlFormat = pkgs.formats.toml { };
|
||||
in
|
||||
{
|
||||
meta.maintainers = [ lib.maintainers.ALameLlama ];
|
||||
|
|
@ -29,6 +30,49 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
rules = lib.mkOption {
|
||||
type = lib.types.attrsOf tomlFormat.type;
|
||||
default = { };
|
||||
example = lib.literalExpression ''
|
||||
{
|
||||
cargo = {
|
||||
command = "cargo";
|
||||
match_err = [
|
||||
{
|
||||
pattern = [ "run `cargo init` to initialize a new rust project" ];
|
||||
suggest = [ "cargo init" ];
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
_PR_GENERAL = {
|
||||
match_err = [
|
||||
{
|
||||
pattern = [ "permission denied" ];
|
||||
suggest = [
|
||||
"#[executable(sudo), !cmd_contains(sudo)]\nsudo {{command}}"
|
||||
];
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
'';
|
||||
description = ''
|
||||
Runtime rule files written to
|
||||
{file}`$XDG_CONFIG_HOME/pay-respects/rules/<name>.toml`.
|
||||
|
||||
Attribute names map to filenames. For example, setting `rules.cargo = { ... };`
|
||||
creates {file}`$XDG_CONFIG_HOME/pay-respects/rules/cargo.toml`.
|
||||
The filename must match the command name, except for `_PR_GENERAL`.
|
||||
|
||||
See <https://github.com/iffse/pay-respects/blob/main/rules.md>
|
||||
for runtime rule syntax and behavior.
|
||||
|
||||
Note that these rules are only applied when the runtime-rules module is
|
||||
available to `pay-respects`.
|
||||
'';
|
||||
};
|
||||
|
||||
enableBashIntegration = lib.hm.shell.mkBashIntegrationOption { inherit config; };
|
||||
|
||||
enableFishIntegration = lib.hm.shell.mkFishIntegrationOption { inherit config; };
|
||||
|
|
@ -41,6 +85,13 @@ in
|
|||
config = lib.mkIf cfg.enable {
|
||||
home.packages = [ cfg.package ];
|
||||
|
||||
xdg.configFile = lib.mapAttrs' (
|
||||
name: rule:
|
||||
lib.nameValuePair "pay-respects/rules/${name}.toml" {
|
||||
source = tomlFormat.generate "pay-respects-rule-${name}.toml" rule;
|
||||
}
|
||||
) cfg.rules;
|
||||
|
||||
programs = {
|
||||
bash.initExtra = lib.mkIf cfg.enableBashIntegration ''
|
||||
eval "$(${payRespectsCmd} bash ${cfgOptions})"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue