2020-02-23 21:49:50 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.pet;
|
|
|
|
|
|
|
|
format = pkgs.formats.toml { };
|
|
|
|
|
|
|
|
snippetType = types.submodule {
|
|
|
|
options = {
|
|
|
|
description = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
example = "Count the number of commits in the current branch";
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2020-02-23 21:49:50 +01:00
|
|
|
Description of the snippet.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
command = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
example = "git rev-list --count HEAD";
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2020-02-23 21:49:50 +01:00
|
|
|
The command.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
output = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
example = "473";
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2020-02-23 21:49:50 +01:00
|
|
|
Example output of the command.
|
|
|
|
'';
|
|
|
|
};
|
2021-04-20 22:16:27 +02:00
|
|
|
|
|
|
|
tag = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
2021-10-09 11:14:08 +02:00
|
|
|
example = literalExpression ''["git" "nixpkgs"]'';
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2021-04-20 22:16:27 +02:00
|
|
|
List of tags attached to the command.
|
|
|
|
'';
|
|
|
|
};
|
2020-02-23 21:49:50 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
in {
|
|
|
|
options.programs.pet = {
|
2023-07-01 01:30:13 +02:00
|
|
|
enable = mkEnableOption (lib.mdDoc "pet");
|
2020-02-23 21:49:50 +01:00
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
type = format.type;
|
|
|
|
default = { };
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
Settings written to {file}`config.toml`. See the pet
|
2020-02-23 21:49:50 +01:00
|
|
|
documentation for details.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
selectcmdPackage = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.fzf;
|
2021-10-09 11:14:08 +02:00
|
|
|
defaultText = literalExpression "pkgs.fzf";
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
|
|
|
The package needed for the {var}`settings.selectcmd`.
|
2020-02-23 21:49:50 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
snippets = mkOption {
|
|
|
|
type = types.listOf snippetType;
|
|
|
|
default = [ ];
|
2023-07-01 01:30:13 +02:00
|
|
|
description = lib.mdDoc ''
|
2020-02-23 21:49:50 +01:00
|
|
|
The snippets.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2021-10-27 19:13:07 +02:00
|
|
|
programs.pet.settings = let
|
|
|
|
defaultGeneral = {
|
|
|
|
selectcmd = mkDefault "fzf";
|
|
|
|
snippetfile = config.xdg.configHome + "/pet/snippet.toml";
|
|
|
|
};
|
|
|
|
in if versionAtLeast config.home.stateVersion "21.11" then {
|
|
|
|
General = defaultGeneral;
|
|
|
|
} else
|
|
|
|
defaultGeneral;
|
2020-02-23 21:49:50 +01:00
|
|
|
|
|
|
|
home.packages = [ pkgs.pet cfg.selectcmdPackage ];
|
|
|
|
|
|
|
|
xdg.configFile = {
|
2021-10-27 19:13:07 +02:00
|
|
|
"pet/config.toml".source = format.generate "config.toml"
|
|
|
|
(if versionAtLeast config.home.stateVersion "21.11" then
|
|
|
|
cfg.settings
|
|
|
|
else {
|
|
|
|
General = cfg.settings;
|
|
|
|
});
|
2022-12-01 17:11:46 +01:00
|
|
|
"pet/snippet.toml" = mkIf (cfg.snippets != [ ]) {
|
|
|
|
source = format.generate "snippet.toml" { snippets = cfg.snippets; };
|
|
|
|
};
|
2020-02-23 21:49:50 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|