{
  config,
  lib,
  ...
}: let
  cfg = config.marleyos.programs.bat;
in {
  options.marleyos.programs.bat.enable = lib.mkEnableOption "bat";

  config = lib.mkIf cfg.enable {
    programs.bat = {
      enable = true;

      config = {
        style = "auto";
      };
    };

    programs.fish = {
      functions = {
        cat = {
          wraps = "bat";
          body =
            # fish
            "bat $argv";
        };

        cath = {
          wraps = "bat";
          body =
            # fish
            "bat --plain --language=help $argv";
        };
      };
    };

    home.shellAbbrs = {
      B = {
        position = "anywhere";
        setCursor = true;
        expansion =
          # fish
          "% | bat";
      };

      "-h" = {
        position = "anywhere";
        expansion =
          # fish
          "-h | cath";
      };

      "--help" = {
        position = "anywhere";
        expansion =
          # fish
          "--help | cath";
      };

      help = {
        position = "anywhere";
        expansion =
          # fish
          "help | cath";
      };
    };
  };
}
