# Credits to raf, his flake is in the README.md
{
  config,
  lib,
  ...
}: let
  inherit (builtins) map;
  inherit (config.meta.mainUser) username;
  hmCfg = config.home-manager.users.${username};

  inherit (lib.strings) concatStrings;
in {
  home-manager.users.${username} = let
    elemsConcatted = concatStrings (
      map (s: "\$${s}") [
        "hostname"
        "username"
        "directory"
        "shell"
        "nix_shell"
        "git_branch"
        "git_commit"
        "git_state"
        "git_status"
        "jobs"
        "cmd_duration"
      ]
    );
  in {
    home.sessionVariables = {
      STARSHIP_CACHE = "${hmCfg.home.homeDirectory}/.cache/starship";
    };
    programs.starship = {
      enable = true;
      enableFishIntegration = true;
      enableTransience = true;
      settings = {
        scan_timeout = 2;
        command_timeout = 2000; # nixpkgs makes starship implode with lower values
        add_newline = false;
        line_break.disabled = false;

        format = "${elemsConcatted}\n$character";

        hostname = {
          ssh_only = true;
          disabled = false;
          format = "@[$hostname](bold blue) "; # the whitespace at the end is actually important
        };

        # configure specific elements
        character = {
          error_symbol = "[ÓäÖ](bold red)";
          success_symbol = "[ÓäÖ](bold green)";
          vicmd_symbol = "[Óò´](bold yellow)";
          format = "$symbol [|](bold bright-black) ";
        };

        username = {
          format = "[$user]($style) in ";
        };

        directory = {
          truncation_length = 2;

          # removes the read_only symbol from the format, it doesn't play nicely with my folder icon
          format = "[ÔÅº ](bold green) [$path]($style) ";
        };

        # git
        git_commit.commit_hash_length = 7;
        git_branch.style = "bold purple";
        git_status = {
          style = "red";
          ahead = "‚á° ";
          behind = "‚á£ ";
          conflicted = "Óúß ";
          renamed = "¬ª";
          deleted = "‚úò ";
          diverged = "‚áÜ ";
          modified = "!";
          stashed = "‚â°";
          staged = "+";
          untracked = "?";
        };

        # language configurations
        # the whitespaces at the end *are* necessary for proper formatting
        lua.symbol = "[Óò† ](blue) ";
        python.symbol = "[Óúº ](blue) ";
        rust.symbol = "[Óû® ](red) ";
        nix_shell.symbol = "[Û±ÑÖ ](blue) ";
        golang.symbol = "[Û∞üì ](blue)";
        c.symbol = "[Óòû ](black)";
        nodejs.symbol = "[Û∞éô ](yellow)";

        package.symbol = "üì¶ ";
      };
    };
  };
}
