2020-02-23 20:49:50 +00: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 23:45:18 +00:00
|
|
|
description = ''
|
2020-02-23 20:49:50 +00:00
|
|
|
Description of the snippet.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
command = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
example = "git rev-list --count HEAD";
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2020-02-23 20:49:50 +00:00
|
|
|
The command.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
output = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
|
|
|
example = "473";
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2020-02-23 20:49:50 +00:00
|
|
|
Example output of the command.
|
|
|
|
'';
|
|
|
|
};
|
2021-04-20 20:16:27 +00:00
|
|
|
|
|
|
|
tag = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [ ];
|
2021-10-09 09:14:08 +00:00
|
|
|
example = literalExpression ''["git" "nixpkgs"]'';
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2021-04-20 20:16:27 +00:00
|
|
|
List of tags attached to the command.
|
|
|
|
'';
|
|
|
|
};
|
2020-02-23 20:49:50 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
in {
|
|
|
|
options.programs.pet = {
|
2023-07-01 23:45:18 +00:00
|
|
|
enable = mkEnableOption "pet";
|
2020-02-23 20:49:50 +00:00
|
|
|
|
|
|
|
settings = mkOption {
|
|
|
|
type = format.type;
|
|
|
|
default = { };
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2023-06-30 23:30:13 +00:00
|
|
|
Settings written to {file}`config.toml`. See the pet
|
2020-02-23 20:49:50 +00:00
|
|
|
documentation for details.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
selectcmdPackage = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = pkgs.fzf;
|
2021-10-09 09:14:08 +00:00
|
|
|
defaultText = literalExpression "pkgs.fzf";
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2023-06-30 23:30:13 +00:00
|
|
|
The package needed for the {var}`settings.selectcmd`.
|
2020-02-23 20:49:50 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
snippets = mkOption {
|
|
|
|
type = types.listOf snippetType;
|
|
|
|
default = [ ];
|
2023-07-01 23:45:18 +00:00
|
|
|
description = ''
|
2020-02-23 20:49:50 +00:00
|
|
|
The snippets.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2021-10-27 17:13:07 +00: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 20:49:50 +00:00
|
|
|
|
|
|
|
home.packages = [ pkgs.pet cfg.selectcmdPackage ];
|
|
|
|
|
|
|
|
xdg.configFile = {
|
2021-10-27 17:13:07 +00: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 16:11:46 +00:00
|
|
|
"pet/snippet.toml" = mkIf (cfg.snippets != [ ]) {
|
|
|
|
source = format.generate "snippet.toml" { snippets = cfg.snippets; };
|
|
|
|
};
|
2020-02-23 20:49:50 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|