2024-11-13 15:58:18 +00:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
pkgs,
|
|
|
|
lib,
|
|
|
|
...
|
|
|
|
}:
|
|
|
|
let
|
|
|
|
inherit (lib)
|
|
|
|
getExe
|
2024-11-21 20:26:50 +00:00
|
|
|
literalExpression
|
2024-11-13 15:58:18 +00:00
|
|
|
maintainers
|
|
|
|
mkEnableOption
|
|
|
|
mkIf
|
2024-11-21 20:26:50 +00:00
|
|
|
mkMerge
|
2024-11-13 15:58:18 +00:00
|
|
|
mkOption
|
2024-12-11 13:09:30 -03:00
|
|
|
mkPackageOption
|
2024-11-15 17:56:54 +00:00
|
|
|
optionalString
|
2024-11-13 15:58:18 +00:00
|
|
|
types
|
|
|
|
;
|
2024-11-21 20:26:50 +00:00
|
|
|
inherit (types) listOf str;
|
|
|
|
|
2024-11-13 15:58:18 +00:00
|
|
|
cfg = config.programs.pay-respects;
|
|
|
|
|
2024-11-21 20:26:50 +00:00
|
|
|
settingsFormat = pkgs.formats.toml { };
|
|
|
|
inherit (settingsFormat) generate type;
|
|
|
|
|
2024-11-13 15:58:18 +00:00
|
|
|
initScript =
|
|
|
|
shell:
|
|
|
|
if (shell != "fish") then
|
|
|
|
''
|
2024-12-11 13:09:30 -03:00
|
|
|
eval $(${getExe cfg.package} ${shell} --alias ${cfg.alias})
|
2024-11-13 15:58:18 +00:00
|
|
|
''
|
|
|
|
else
|
|
|
|
''
|
2024-12-11 13:09:30 -03:00
|
|
|
${getExe cfg.package} ${shell} --alias ${cfg.alias} | source
|
2024-11-13 15:58:18 +00:00
|
|
|
'';
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
programs.pay-respects = {
|
|
|
|
enable = mkEnableOption "pay-respects, an app which corrects your previous console command";
|
|
|
|
|
2024-12-11 13:09:30 -03:00
|
|
|
package = mkPackageOption pkgs "pay-respects" { };
|
|
|
|
|
2024-11-13 15:58:18 +00:00
|
|
|
alias = mkOption {
|
|
|
|
default = "f";
|
|
|
|
type = str;
|
|
|
|
description = ''
|
|
|
|
`pay-respects` needs an alias to be configured.
|
|
|
|
The default value is `f`, but you can use anything else as well.
|
|
|
|
'';
|
|
|
|
};
|
2024-11-21 20:26:50 +00:00
|
|
|
runtimeRules = mkOption {
|
|
|
|
type = listOf type;
|
|
|
|
default = [ ];
|
|
|
|
example = literalExpression ''
|
|
|
|
[
|
|
|
|
{
|
|
|
|
command = "xl";
|
|
|
|
match_err = [
|
|
|
|
{
|
|
|
|
pattern = [
|
|
|
|
"Permission denied"
|
|
|
|
];
|
|
|
|
suggest = [
|
|
|
|
'''
|
|
|
|
#[executable(sudo), !cmd_contains(sudo), err_contains(libxl: error:)]
|
|
|
|
sudo {{command}}
|
|
|
|
'''
|
|
|
|
];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
List of rules to be added to `/etc/xdg/pay-respects/rules`.
|
|
|
|
`pay-respects` will read the contents of these generated rules to recommend command corrections.
|
|
|
|
Each rule module should start with the `command` attribute that specifies the command name. See the [upstream documentation](https://codeberg.org/iff/pay-respects/src/branch/main/rules.md) for more information.
|
|
|
|
'';
|
|
|
|
};
|
2024-11-13 15:58:18 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2024-11-21 20:26:50 +00:00
|
|
|
environment = mkMerge (
|
|
|
|
[
|
|
|
|
{
|
2024-12-11 13:09:30 -03:00
|
|
|
systemPackages = [ cfg.package ];
|
2024-11-21 20:26:50 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
++ map (rule: {
|
|
|
|
etc."xdg/pay-respects/rules/${rule.command}.toml".source = generate "${rule.command}.toml" rule;
|
|
|
|
}) cfg.runtimeRules
|
|
|
|
);
|
2024-11-13 15:58:18 +00:00
|
|
|
|
|
|
|
programs = {
|
|
|
|
bash.interactiveShellInit = initScript "bash";
|
2024-11-15 17:56:54 +00:00
|
|
|
fish.interactiveShellInit = optionalString config.programs.fish.enable (initScript "fish");
|
|
|
|
zsh.interactiveShellInit = optionalString config.programs.zsh.enable (initScript "zsh");
|
2024-11-13 15:58:18 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
meta.maintainers = with maintainers; [ sigmasquadron ];
|
|
|
|
}
|