home-manager/modules/programs/feh.nix

84 lines
2.4 KiB
Nix
Raw Normal View History

2017-09-04 14:35:23 +00:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.programs.feh;
bindingsOf = t: with types; attrsOf (nullOr (either t (listOf t)));
renderBindings = bindings:
let
enabled = filterAttrs (n: v: v != null) bindings;
disabled = filterAttrs (n: v: v == null) bindings;
render = mapAttrsToList renderBinding;
in concatStringsSep "\n" (render disabled ++ render enabled);
renderBinding = func: key:
if key == null then
func
else if isList key then
concatStringsSep " " ([ func ] ++ map toString key)
else
"${func} ${toString key}";
2017-09-04 14:35:23 +00:00
2020-02-01 23:39:17 +00:00
in {
2017-09-04 14:35:23 +00:00
options.programs.feh = {
enable = mkEnableOption "feh - a fast and light image viewer";
package = mkPackageOption pkgs "feh" { };
buttons = mkOption {
2020-02-01 23:39:17 +00:00
default = { };
type = with types; bindingsOf (either str int);
2020-02-01 23:39:17 +00:00
example = {
zoom_in = 4;
zoom_out = "C-4";
prev_img = [ 3 "C-3" ];
2020-02-01 23:39:17 +00:00
};
description = ''
Override feh's default mouse button mapping. If you want to disable an
action, set its value to null. If you want to bind multiple buttons to
an action, set its value to a list.
See <link xlink:href="https://man.finalrewind.org/1/feh/#x425554544f4e53"/> for
default bindings and available commands.
'';
};
2017-09-04 14:35:23 +00:00
keybindings = mkOption {
2020-02-01 23:39:17 +00:00
default = { };
type = bindingsOf types.str;
2020-02-01 23:39:17 +00:00
example = {
zoom_in = "plus";
zoom_out = "minus";
prev_img = [ "h" "Left" ];
2020-02-01 23:39:17 +00:00
};
2017-09-04 14:35:23 +00:00
description = ''
Override feh's default keybindings. If you want to disable a keybinding
set its value to null. If you want to bind multiple keys to an action,
set its value to a list.
2017-09-04 14:35:23 +00:00
See <link xlink:href="https://man.finalrewind.org/1/feh/#x4b455953"/> for
default bindings and available commands.
'';
};
};
config = mkIf cfg.enable {
2020-02-01 23:39:17 +00:00
assertions = [{
assertion = ((filterAttrs (n: v: v == "") cfg.keybindings) == { });
message =
"To disable a keybinding, use `null` instead of an empty string.";
}];
home.packages = [ cfg.package ];
2017-09-04 14:35:23 +00:00
xdg.configFile."feh/buttons" =
mkIf (cfg.buttons != { }) { text = renderBindings cfg.buttons + "\n"; };
2017-09-04 14:35:23 +00:00
xdg.configFile."feh/keys" = mkIf (cfg.keybindings != { }) {
text = renderBindings cfg.keybindings + "\n";
};
2017-09-04 14:35:23 +00:00
};
}