{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.home.roles.starship;
in
{
  options.home.roles.starship = {
    enable = mkEnableOption "starship cross-shell prompt";
  };

  config = mkIf cfg.enable {
    programs.starship = {
      enable = true;
      enableBashIntegration = true;
      enableZshIntegration = true;

      settings = {
        add_newline = true;

        character = {
          success_symbol = "[>](bold green)";
          error_symbol = "[x](bold red)";
          vimcmd_symbol = "[<](bold green)";
        };

        directory = {
          truncation_length = 4;
          truncate_to_repo = true;
        };

        git_branch = {
          symbol = "";
          format = "[$symbol$branch(:$remote_branch)]($style) ";
        };

        git_status = {
          format = "([$all_status$ahead_behind]($style) )";
        };

        nix_shell = {
          symbol = "";
          format = "[$symbol$state( \\($name\\))]($style) ";
        };

        cmd_duration = {
          min_time = 2000;
          format = "[$duration]($style) ";
        };

        # Disable modules that are noisy or rarely needed
        package.disabled = true;
        nodejs.disabled = true;
        python.disabled = true;
        ruby.disabled = true;
        java.disabled = true;
        golang.disabled = true;
        rust.disabled = true;
        php.disabled = true;
        lua.disabled = true;
        perl.disabled = true;
        terraform.disabled = true;
        kubernetes.disabled = true;
        docker_context.disabled = true;
        aws.disabled = true;
        gcloud.disabled = true;
        azure.disabled = true;
      };
    };
  };
}
