2022-03-28 17:19:38 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.programs.pistol;
|
|
|
|
|
2022-12-10 21:52:30 +01: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;
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Preview command for files matched by this association.";
|
2022-12-10 21:52:30 +01:00
|
|
|
};
|
2022-03-28 17:19:38 +02:00
|
|
|
|
2022-12-10 21:52:30 +01:00
|
|
|
fpath = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "File path regex that this association should match.";
|
2022-12-10 21:52:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
mime = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "";
|
2023-07-02 01:45:18 +02:00
|
|
|
description = "Mime type regex that this association should match.";
|
2022-12-10 21:52:30 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2022-03-28 17:19:38 +02:00
|
|
|
in {
|
2022-12-10 21:52:30 +01:00
|
|
|
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 = {
|
2023-07-02 01:45:18 +02:00
|
|
|
enable = mkEnableOption "file previewer for terminal file managers";
|
2022-03-28 17:19:38 +02:00
|
|
|
|
2022-12-10 21:52:30 +01:00
|
|
|
associations = mkOption {
|
|
|
|
type = types.listOf association;
|
|
|
|
default = [ ];
|
2022-03-28 17:19:38 +02:00
|
|
|
example = literalExpression ''
|
2022-12-10 21:52:30 +01: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 17:19:38 +02:00
|
|
|
'';
|
2023-07-02 01:45:18 +02:00
|
|
|
description = ''
|
2022-12-10 21:52:30 +01:00
|
|
|
Associations written to the Pistol configuration at
|
2023-07-01 01:30:13 +02:00
|
|
|
{file}`$XDG_CONFIG_HOME/pistol/pistol.conf`.
|
2022-03-28 17:19:38 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable (mkMerge [
|
2022-12-10 21:52:30 +01: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 17:19:38 +02:00
|
|
|
|
2022-12-10 21:52:30 +01: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;
|
|
|
|
})
|
|
|
|
|
2022-12-10 21:52:30 +01:00
|
|
|
(mkIf (cfg.associations != [ ] && !pkgs.stdenv.hostPlatform.isDarwin) {
|
2022-03-28 17:19:38 +02:00
|
|
|
xdg.configFile."pistol/pistol.conf".text = configFile;
|
|
|
|
})
|
|
|
|
]);
|
|
|
|
}
|