1
0
Fork 0
mirror of https://github.com/nix-community/home-manager synced 2024-12-25 03:09:47 +01:00
home-manager/modules/programs/pistol.nix

86 lines
2.3 KiB
Nix
Raw Normal View History

2022-03-28 17:19:38 +02:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.pistol;
configFile = concatStringsSep "\n" (map ({ fpath, mime, command }:
if fpath == "" then "${mime} ${command}" else "fpath ${fpath} ${command}")
cfg.associations);
association = types.submodule {
options = {
command = mkOption {
type = types.str;
description = "Preview command for files matched by this association.";
};
2022-03-28 17:19:38 +02:00
fpath = mkOption {
type = types.str;
default = "";
description = "File path regex that this association should match.";
};
mime = mkOption {
type = types.str;
default = "";
description = "Mime type regex that this association should match.";
};
};
};
2022-03-28 17:19:38 +02:00
in {
imports = [
(mkRemovedOptionModule [ "programs" "pistol" "config" ]
"Pistol is now configured with programs.pistol.associations.")
];
2022-03-28 17:19:38 +02:00
meta.maintainers = [ hm.maintainers.mtoohey ];
options.programs.pistol = {
enable = mkEnableOption "file previewer for terminal file managers";
2022-03-28 17:19:38 +02:00
associations = mkOption {
type = types.listOf association;
default = [ ];
2022-03-28 17:19:38 +02:00
example = literalExpression ''
[
{ mime = "application/json"; command = "bat %pistol-filename%"; }
{ mime = "application/*"; command = "hexyl %pistol-filename%"; }
{ fpath = ".*.md$"; command = "sh: bat --paging=never --color=always %pistol-filename% | head -8"; }
]
2022-03-28 17:19:38 +02:00
'';
description = ''
Associations written to the Pistol configuration at
2022-03-28 17:19:38 +02:00
<filename>$XDG_CONFIG_HOME/pistol/pistol.conf</filename>.
'';
};
};
config = mkIf cfg.enable (mkMerge [
{
assertions = [{
assertion = all ({ fpath, mime, ... }:
(fpath != "" && mime == "") || (fpath == "" && mime != ""))
cfg.associations;
message = ''
Each entry in programs.pistol.associations must contain exactly one
of fpath or mime.
'';
}];
home.packages = [ pkgs.pistol ];
}
2022-03-28 17:19:38 +02:00
(mkIf (cfg.associations != [ ] && pkgs.stdenv.hostPlatform.isDarwin) {
2022-03-28 17:19:38 +02:00
home.file."Library/Application Support/pistol/pistol.conf".text =
configFile;
})
(mkIf (cfg.associations != [ ] && !pkgs.stdenv.hostPlatform.isDarwin) {
2022-03-28 17:19:38 +02:00
xdg.configFile."pistol/pistol.conf".text = configFile;
})
]);
}