{ config, lib, ... }:
{
  programs.git.enable = true;
  #programs.git.settings.user.name = "pbsds"
  programs.git.settings.user.name = "Peder Bergebakken Sundt";
  programs.git.settings.user.email = "pbsds@hotmail.com";

  programs.delta.enable = true;
  programs.delta.enableGitIntegration = true;
  programs.delta.options = {
    # Delta uses ~/.gitconfig even when not invoked by git
    tabs = 4;
    max-line-length = 0;
    features.syntax-theme = lib.mkIf config.programs.bat.enable config.programs.bat.config.theme;
  };

  # # sign commits with ssh key
  # programs.git.settings.gpg.format = "ssh";
  # programs.git.signing.key = "${config.home.homeDirectory}/.ssh/my-key.pub";
  # programs.git.signing.signByDefault = true;

  # https://jvns.ca/blog/2024/02/16/popular-git-config-options/
  programs.git.settings.rerere.enabled = true;
  #programs.git.settings.help.autocorrect = "prompt";
  programs.git.settings.transfer.fsckobjects = true;
  programs.git.settings.fetch.fsckobjects = true;
  programs.git.settings.receive.fsckObjects = true;
  programs.git.settings.branch.sort = "-committerdate";
  programs.git.settings.tag.sort = "taggerdate";
  programs.git.settings.fetch.prune = true;
  programs.git.settings.fetch.prunetags = true;
  programs.git.settings.log.date = "iso";
  # programs.git.settings.interactive.singleKey = true;

  programs.git.iniContent.init.defaultBranch = "main";
  programs.git.ignores = [
    #".envrc"
    ".direnv"
    ".remote.toml"
    ".remoteenv"
    ".zed"
    "result"
    "result-*"
    "results"
    "results-*"
    "__pycache__"
    "*.pyc"
  ];

  home.shellAliases = {
    # git gud
    gs     = "git status";
    gl     = "git --no-pager log --oneline --color -n30";
    glg    = "git log --color --all --decorate --oneline --graph";
    gpra   = "git pull --rebase --autostash";
    gprau  = ''git pull --rebase --autostash upstream "$(git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')"'';
    gd     = "git diff";
    gds    = "git diff --staged";
    gdwd   = "git -c core.pager=\"$PAGER\" diff --word-diff"; # delta does not support --word-diff
    gdwdr  = "git -c core.pager=\"$PAGER\" diff --word-diff --word-diff-regex=.";
    gdwds  = "git -c core.pager=\"$PAGER\" diff --staged --word-diff";
    gdswd  = "git -c core.pager=\"$PAGER\" diff --staged --word-diff";
    gdwdrs = "git -c core.pager=\"$PAGER\" diff --staged --word-diff --word-diff-regex=.";
    gdswdr = "git -c core.pager=\"$PAGER\" diff --staged --word-diff --word-diff-regex=.";
    #gcp    = "git cherry-pick";
    gca    = "git commit --amend";
    gcara  = "git commit --amend --reset-author";
    gc     = "git branch | cut -c2- | gum choose | xargs -d'\n' --no-run-if-empty git checkout";
    gbrm   = "git fetch origin; git branch --merged | cut -c3- | grep -vE '^(main|master)$' | gum choose --no-limit --header 'Which branches to delete:' | xargs -n'\n' --no-run-if-empty git branch -D";
    #gb     = "git blame";
    #gpo    = "git push origin";
    #gpf    = "git push --force-with-lease --force-if-includes";
  };

}
