{ lib
, config
, pkgs
, ...
}:
let
  inherit (lib) mkEnableOption mkIf;

  cfg = config.plusultra.cli-apps.fish;
in
{
  options.plusultra.cli-apps.fish = {
    enable = mkEnableOption "FISH shell";
  };

  config = mkIf cfg.enable {
    programs.fish = {
      enable = true;
      interactiveShellInit = ''
        function msh --wraps mosh --description 'mosh with tmux'
          if not set -q argv[1]
            echo 'Usage: msh [user@]host [command]'
          else
            ${pkgs.mosh}/bin/mosh $argv -- tmux new-session -A -s 0
          end
        end
      '';

      plugins = [{
        name = "foreign-env";
        src = pkgs.fetchFromGitHub {
          owner = "oh-my-fish";
          repo = "plugin-foreign-env";
          rev = "dddd9213272a0ab848d474d0cbde12ad034e65bc";
          sha256 = "00xqlyl3lffc5l0viin1nyp819wf81fncqyz87jx8ljjdhilmgbs";
        };
      }];

      shellInit =
        ''
          # nix
          if test -e /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
              fenv source /nix/var/nix/profiles/default/etc/profile.d/nix-daemon.sh
          end

          # home-manager
          if test -e $HOME/.nix-profile/etc/profile.d/hm-session-vars.sh
              fenv source $HOME/.nix-profile/etc/profile.d/hm-session-vars.sh
          end
        '';
    };
  };
}
