mirror of
https://github.com/nix-community/home-manager
synced 2024-12-22 02:53:16 +00:00
b7eb400d41
This pull requests refactors the pistol configuration options, since the current options are deficient in a few ways. Closes #3486
85 lines
2.3 KiB
Nix
85 lines
2.3 KiB
Nix
{ 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.";
|
|
};
|
|
|
|
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.";
|
|
};
|
|
};
|
|
};
|
|
in {
|
|
imports = [
|
|
(mkRemovedOptionModule [ "programs" "pistol" "config" ]
|
|
"Pistol is now configured with programs.pistol.associations.")
|
|
];
|
|
|
|
meta.maintainers = [ hm.maintainers.mtoohey ];
|
|
|
|
options.programs.pistol = {
|
|
enable = mkEnableOption "file previewer for terminal file managers";
|
|
|
|
associations = mkOption {
|
|
type = types.listOf association;
|
|
default = [ ];
|
|
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"; }
|
|
]
|
|
'';
|
|
description = ''
|
|
Associations written to the Pistol configuration at
|
|
<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 ];
|
|
}
|
|
|
|
(mkIf (cfg.associations != [ ] && pkgs.stdenv.hostPlatform.isDarwin) {
|
|
home.file."Library/Application Support/pistol/pistol.conf".text =
|
|
configFile;
|
|
})
|
|
|
|
(mkIf (cfg.associations != [ ] && !pkgs.stdenv.hostPlatform.isDarwin) {
|
|
xdg.configFile."pistol/pistol.conf".text = configFile;
|
|
})
|
|
]);
|
|
}
|