{
  config,
  lib,
  ...
}: let
  cfg = config.hive.ranger;
in {
  options.hive.ranger = {
    enable = lib.mkEnableOption "Enable ranger";
  };
  config = lib.mkIf cfg.enable {
    programs.ranger = {
      enable = true;
      settings = {
        preview_images = true;
        preview_images_method =
          if config.programs.kitty.enable
          then "kitty"
          else "ueberzug";
      };
      extraConfig = lib.strings.concatStringsSep "\n" [
        "default_linemode devicons"
      ];
      mappings = {
        f = "console fzf_filter%space";
      };
      plugins =
        [
          {
            name = "ranger_fzf_filter";
            src = builtins.fetchGit {
              url = "https://github.com/MuXiu1997/ranger-fzf-filter";
              rev = "bf16de2e4ace415b685ff7c58306d0c5146f9f43";
            };
          }
          {
            name = "ranger_archives";
            src = builtins.fetchGit {
              url = "https://github.com/maximtrp/ranger-archives";
              rev = "b4e136b24fdca7670e0c6105fb496e5df356ef25";
            };
          }
          {
            name = "ranger_devicons";
            src = builtins.fetchGit {
              url = "https://github.com/alexanderjeurissen/ranger_devicons";
              rev = "f227f212e14996fbb366f945ec3ecaf5dc5f44b0";
            };
          }
        ]
        ++ (
          if config.services.kdeconnect.enable
          then
            lib.lists.singleton
            {
              name = "ranger_kdeconnect.py";
              src =
                builtins.fetchGit {
                  url = "https://github.com/bwconrad/ranger-kdeconnect";
                  rev = "710c600bb894fed3e293f6518930c16a494dd154";
                }
                + "/kdeconnect_send.py";
            }
          else []
        );
    };
  };
}
