{
  lib,
  pkgs,
  config,
  system,
  ...
}:
let
  isDarwin = lib.strings.hasSuffix "-darwin" system;
  isLinux = lib.strings.hasSuffix "-darwin" system;
  shell = pkgs.bashInteractive;
  shellArgs = [
    "-c"
    (lib.getExe pkgs.zellij)
  ];
in
{
  config = lib.mkIf (config.khscodes.khs.enable && config.khscodes.desktop.enable) {
    programs.alacritty = {
      enable = true;
      settings = {
        terminal =
          {
            shell = {
              program = "${shell}${shell.shellPath}";
              args = shellArgs;
            };
          }
          // lib.attrsets.optionalAttrs isDarwin {
            osc52 = "CopyPaste";
          };
        scrolling = {
          history = 100000;
        };
        window = {
          padding = {
            x = 2;
            y = 0;
          };
        };
        bell = {
          animation = "EaseOutExpo";
        };
        hints = {
          enabled = [
            {
              regex = "(ipfs:|ipns:|magnet:|mailto:|gemini:|gopher:|https:|http:|news:|file:|git:|ssh:|ftp:)[^\\u0000-\\u001F\\u007F-\\u009F<>\"\\\\s{-}\\\\^⟨⟩`]+";
              command = if isLinux then "xdg-open" else "open";
              post_processing = true;
              mouse = {
                enabled = true;
                mods = "Control";
              };
            }
          ];
        };
        window = {
          option_as_alt = "OnlyLeft";
        };
        env = {
          TERM = "xterm-256color";
        };
        keyboard.bindings =
          [
            {
              key = "T";
              mods = "Control|Shift";
              action = "SpawnNewInstance";
            }
            {
              key = "W";
              mods = "Control|Shift";
              action = "Quit";
            }
            {
              key = "Plus";
              mods = "Control";
              action = "IncreaseFontSize";
            }
            {
              key = "Minus";
              mods = "Control";
              action = "DecreaseFontSize";
            }
            {
              key = "Key0";
              mods = "Control";
              action = "ResetFontSize";
            }
            {
              key = "C";
              mods = "Super";
              action = "None";
            }
          ]
          ++ lib.lists.optionals isDarwin [
            {
              key = "N";
              mods = "Command";
              action = "SpawnNewInstance";
            }
            # Allow zellij to receive the keys, to make copy/pasting work in darwin
            {
              key = "C";
              mods = "Command";
              action = "ReceiveChar";
            }
          ];
      };
    };
    stylix.targets.alacritty.enable = true;
  };
}
