home-manager/modules/programs/feh.nix
Emily 36a53d9f26 treewide: convert all option docs to Markdown
This process was automated by [my fork of `nix-doc-munge`]. All
conversions were automatically checked to produce the same DocBook
result when converted back, modulo minor typographical/formatting
differences on the acceptable-to-desirable spectrum.

To reproduce this commit, run:

  $ NIX_PATH=nixpkgs=flake:nixpkgs/e7e69199f0372364a6106a1e735f68604f4c5a25 \
    nix shell nixpkgs#coreutils \
    -c find . -name '*.nix' \
    -exec nix run -- github:emilazy/nix-doc-munge/98dadf1f77351c2ba5dcb709a2a171d655f15099 \
    {} +
  $ ./format

[my fork of `nix-doc-munge`]: https://github.com/emilazy/nix-doc-munge/tree/home-manager
2023-07-17 18:40:56 +01:00

84 lines
2.3 KiB
Nix

{ 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}";
in {
options.programs.feh = {
enable = mkEnableOption (lib.mdDoc "feh - a fast and light image viewer");
package = mkPackageOptionMD pkgs "feh" { };
buttons = mkOption {
default = { };
type = with types; bindingsOf (either str int);
example = {
zoom_in = 4;
zoom_out = "C-4";
prev_img = [ 3 "C-3" ];
};
description = lib.mdDoc ''
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 <https://man.finalrewind.org/1/feh/#x425554544f4e53> for
default bindings and available commands.
'';
};
keybindings = mkOption {
default = { };
type = bindingsOf types.str;
example = {
zoom_in = "plus";
zoom_out = "minus";
prev_img = [ "h" "Left" ];
};
description = lib.mdDoc ''
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.
See <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 = [ cfg.package ];
xdg.configFile."feh/buttons" =
mkIf (cfg.buttons != { }) { text = renderBindings cfg.buttons + "\n"; };
xdg.configFile."feh/keys" = mkIf (cfg.keybindings != { }) {
text = renderBindings cfg.keybindings + "\n";
};
};
}