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

let
  cfg = config.sydnix.users.crumb.git;

  options.sydnix.users.crumb.git.enable =
    lib.mkEnableOption "Git, à la crumb";

  # TODO: Move somewhere else.
  my-email = "lomiskiam@gmail.com";
  my-name = "Madeleine Sydney";
in {
  options.sydnix.users.crumb.git.enable =
    lib.mkEnableOption "Git, à la crumb";

  config = lib.mkIf cfg.enable (
    lib.mkMerge [
      {
        ### Git
        programs.git = {
          enable = true;
          userEmail = my-email;
          userName = my-name;
        };

        home.shellAliases = {
          ga   = "git add";
          gb   = "git branch";
          gc   = "git commit";
          gcl  = "git clone";
          gco  = "git checkout";
          gd   = "git diff";
          gl   = "git log";
          glo  = "git log --pretty=oneline";
          glol = "git log --graph --oneline --decorate";
          gp   = "git push";
          gr   = "git remote";
          grs  = "git remote show";
          gs   = "git status";
          gtd  = "git tag --delete";
        };
      }
      {
        ### Jujutsu
        programs.jujutsu = {
          enable = true;
          settings.user = {
            email = my-email;
            name = my-name;
          };
        };

        home.shellAliases = {
          jb   = "jj bookmark";
          jdi  = "jj diff";
          jd   = "jj describe";
          je   = "jj edit";
          jgcl = "jj git clone";
          jgp  = "jj git push";
          jgr  = "jj git remote";
          jl   = "jj log";
          jn   = "jj new";
          js   = "jj status";
          jsp  = "jj split";
        };
      }
      {
        ### Github CLI
        programs.gh = {
          enable = true;
          settings = {
            git_protocol = "ssh";
          };
        };

        sydnix.sops.secrets.github-oauth = {};
      }
      {
        ### Gitlab CLI
        programs.glab.enable = true;
      }
    ]);
}
