aboutsummaryrefslogtreecommitdiff
path: root/home-manager/modules/programs/feh.nix
blob: b1b33697e958522ec7f0bb76c4221a0ef51bad0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
{ config, lib, pkgs, ... }:

with lib;

let

  cfg = config.programs.feh;

  disableBinding = func: key: func;
  enableBinding = func: key: "${func} ${toString key}";

in {
  options.programs.feh = {
    enable = mkEnableOption "feh - a fast and light image viewer";

    buttons = mkOption {
      default = { };
      type = with types; attrsOf (nullOr (either str int));
      example = {
        zoom_in = 4;
        zoom_out = "C-4";
      };
      description = ''
        Override feh's default mouse button mapping. If you want to disable an
        action, set its value to null.
        See <link xlink:href="https://man.finalrewind.org/1/feh/#x425554544f4e53"/> for
        default bindings and available commands.
      '';
    };

    keybindings = mkOption {
      default = { };
      type = types.attrsOf (types.nullOr types.str);
      example = {
        zoom_in = "plus";
        zoom_out = "minus";
      };
      description = ''
        Override feh's default keybindings. If you want to disable a keybinding
        set its value to null.
        See <link xlink:href="https://man.finalrewind.org/1/feh/#x4b455953"/> for
        default bindings and available commands.
      '';
    };
  };

  config = mkIf cfg.enable {
    assertions = [{
      assertion = ((filterAttrs (n: v: v == "") cfg.keybindings) == { });
      message =
        "To disable a keybinding, use `null` instead of an empty string.";
    }];

    home.packages = [ pkgs.feh ];

    xdg.configFile."feh/buttons".text = ''
      ${concatStringsSep "\n" (mapAttrsToList disableBinding
        (filterAttrs (n: v: v == null) cfg.buttons))}
      ${concatStringsSep "\n" (mapAttrsToList enableBinding
        (filterAttrs (n: v: v != null) cfg.buttons))}
    '';

    xdg.configFile."feh/keys".text = ''
      ${concatStringsSep "\n" (mapAttrsToList disableBinding
        (filterAttrs (n: v: v == null) cfg.keybindings))}
      ${concatStringsSep "\n" (mapAttrsToList enableBinding
        (filterAttrs (n: v: v != null) cfg.keybindings))}
    '';
  };
}