{
  lib,
  config,
  scope,
  ...
}:
let
  inherit (lib)
    range
    nameValuePair
    mapAttrs'
    mergeAttrsList
    ;
  inherit (builtins) listToAttrs replaceStrings;
  hBinds = {
    H = "left";
    L = "right";
  };
  vBinds = {
    J = "down";
    K = "up";
  };
  makeDirBind =
    mods: cmd: keys:
    mapAttrs' (
      key: dir:
      nameValuePair "${mods}+${key}" {
        action = "${replaceStrings [ "$DIR" ] [ "${dir}" ] "${cmd}"}";
      }
    ) keys;
  makeTagBind =
    mods: cmd:
    listToAttrs (
      map (num: {
        name = "${mods}+${builtins.toString (lib.mod num 10)}";
        value = {
          spawn = [
            "tagctl"
            cmd
            (builtins.toString num)
          ];
        };
      }) (range 1 10)
    );
  getApp = app: lib.singleton (lib.getExe config.apps.${app});
in
scope "user.desktops.niri.binds"
<| mergeAttrsList [
  {
    "Mod+Grave".action = "focus-monitor-next";
    "Mod+Shift+Grave".action = "move-column-to-monitor-next";
    "Mod+Minus".spawn = [
      "tagctl"
      "toggle-tag"
      "99"
    ];
    "Mod+Equal".spawn = [
      "tagctl"
      "toggle-tag"
      "101"
    ];
    "Mod+D".spawn = [
      "qs"
      "ipc"
      "call"
      "launch"
      "toggle"
    ];
    "Mod+F".spawn = (getApp "browser");
    "Mod+E".spawn = (getApp "fm");
    "Mod+Return".spawn = (getApp "terminal");
    "Mod+Shift+E".spawn = [
      "qs"
      "ipc"
      "call"
      "logout"
      "toggle"
    ];
    # "Mod+Equal".spawn = (getAppName "passwordManager"); # niri-tag needs proper scratchpads smh
    "Mod+Shift+Q".action = "close-window";
    "Mod+Shift+S".action = "screenshot";
    "Mod+R".action = "switch-preset-column-width";
    "Mod+Shift+R".action = "maximize-column";
    "XF86AudioLowerVolume".spawn = [
      "volumectl"
      "-u"
      "down"
    ];
    "XF86AudioMute".spawn = [
      "volumectl"
      "toggle-mute"
    ];
    "XF86AudioNext".spawn = [
      "playerctl"
      "next"
    ];
    "XF86AudioPlay".spawn = [
      "playerctl"
      "play-pause"
    ];
    "XF86AudioPrev".spawn = [
      "playerctl"
      "previous"
    ];
    "XF86AudioRaiseVolume".spawn = [
      "volumectl"
      "-u"
      "up"
    ];
    "XF86AudioStop".spawn = [
      "playerctl"
      "stop"
    ];
    "XF86MonBrightnessUp".spawn = [
      "brightnessctl"
      "s"
      "5%+"
    ];
    "XF86MonBrightnessDown".spawn = [
      "brightnessctl"
      "s"
      "5%-"
    ];
    "Mod+Space".action = "switch-focus-between-floating-and-tiling";
    "Mod+Shift+Space".action = "toggle-window-floating";
    "Mod+Ctrl+Space".action = "fullscreen-window";
    "Mod+C".action = "center-window";
  }
  (makeDirBind "Mod" "focus-window-$DIR" vBinds)
  (makeDirBind "Mod" "focus-column-or-monitor-$DIR" hBinds)
  (makeDirBind "Mod+Shift" "consume-or-expel-window-$DIR" hBinds)
  (makeDirBind "Mod+Ctrl" "move-column-$DIR-or-to-monitor-$DIR" hBinds)
  (makeDirBind "Mod+Ctrl" "move-window-$DIR" vBinds)
  (makeTagBind "Mod" "toggle-tag")
  (makeTagBind "Mod+Shift" "toggle")
  (makeTagBind "Mod+Ctrl" "exclusive-tag")
]
