2022-03-28 15:19:38 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.programs.pistol;
|
|
|
|
|
2022-12-10 20:52:30 +00:00
|
|
|
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 15:19:38 +00:00
|
|
|
|
2022-12-10 20:52:30 +00: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 15:19:38 +00:00
|
|
|
in {
|
2022-12-10 20:52:30 +00:00
|
|
|
imports = [
|
|
|
|
(mkRemovedOptionModule [ "programs" "pistol" "config" ]
|
|
|
|
"Pistol is now configured with programs.pistol.associations.")
|
|
|
|
];
|
|
|
|
|
2022-03-28 15:19:38 +00:00
|
|
|
meta.maintainers = [ hm.maintainers.mtoohey ];
|
|
|
|
|
|
|
|
options.programs.pistol = {
|
2022-12-10 20:52:30 +00:00
|
|
|
enable = mkEnableOption "file previewer for terminal file managers";
|
2022-03-28 15:19:38 +00:00
|
|
|
|
2022-12-10 20:52:30 +00:00
|
|
|
associations = mkOption {
|
|
|
|
type = types.listOf association;
|
|
|
|
default = [ ];
|
2022-03-28 15:19:38 +00:00
|
|
|
example = literalExpression ''
|
2022-12-10 20:52:30 +00:00
|
|
|
[
|
|
|
|
{ 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 15:19:38 +00:00
|
|
|
'';
|
|
|
|
description = ''
|
2022-12-10 20:52:30 +00:00
|
|
|
Associations written to the Pistol configuration at
|
2022-03-28 15:19:38 +00:00
|
|
|
<filename>$XDG_CONFIG_HOME/pistol/pistol.conf</filename>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable (mkMerge [
|
2022-12-10 20:52:30 +00:00
|
|
|
{
|
|
|
|
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 15:19:38 +00:00
|
|
|
|
2022-12-10 20:52:30 +00:00
|
|
|
(mkIf (cfg.associations != [ ] && pkgs.stdenv.hostPlatform.isDarwin) {
|
2022-03-28 15:19:38 +00:00
|
|
|
home.file."Library/Application Support/pistol/pistol.conf".text =
|
|
|
|
configFile;
|
|
|
|
})
|
|
|
|
|
2022-12-10 20:52:30 +00:00
|
|
|
(mkIf (cfg.associations != [ ] && !pkgs.stdenv.hostPlatform.isDarwin) {
|
2022-03-28 15:19:38 +00:00
|
|
|
xdg.configFile."pistol/pistol.conf".text = configFile;
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
}
|