{ config, pkgs, lib, ... }: { programs.git = { enable = true; # Basic configuration userName = "Menno van Leeuwen"; userEmail = "menno@vleeuwen.me"; signing = lib.mkIf (!config.isServer) { key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIM+sKpcREOUjwMMSzEWAso6830wbOi8kUxqpuXWw5gHr"; }; # Git settings extraConfig = { init = { defaultBranch = "main"; }; core = { editor = "nvim"; autocrlf = false; filemode = true; ignorecase = false; }; push = { default = "simple"; autoSetupRemote = true; }; pull = { rebase = true; }; branch = { autosetupmerge = "always"; autosetuprebase = "always"; }; merge = { tool = "nvim"; conflictstyle = "diff3"; }; diff = { tool = "delta"; }; color = { ui = "auto"; branch = { current = "yellow reverse"; local = "yellow"; remote = "green"; }; diff = { meta = "yellow bold"; frag = "magenta bold"; old = "red"; new = "green"; }; status = { added = "yellow"; changed = "green"; untracked = "cyan"; }; }; # URL rewrites for SSH url = { "git@github.com:" = { insteadOf = "https://github.com/"; }; "git@gitlab.com:" = { insteadOf = "https://gitlab.com/"; }; "git@git.mvl.sh:" = { insteadOf = "https://git.mvl.sh/"; }; }; # Security gpg = lib.mkIf (!config.isServer) { format = "ssh"; ssh = { program = "/opt/1Password/op-ssh-sign"; }; }; commit = lib.mkIf (!config.isServer) { gpgsign = true; }; # Performance feature = { manyFiles = true; }; index = { version = 4; }; protocol = { version = 2; }; }; # Git aliases aliases = { # Status and info st = "status -sb"; s = "status"; stat = "status"; # Logging l = "log --oneline --graph --decorate"; ll = "log --graph --pretty=format:'%C(yellow)%h%Creset -%C(red)%d%Creset %s %C(green)(%cr) %C(blue)<%an>%Creset' --abbrev-commit --date=relative"; lol = "log --graph --decorate --pretty=oneline --abbrev-commit"; lola = "log --graph --decorate --pretty=oneline --abbrev-commit --all"; hist = "log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short"; # Diff d = "diff"; dc = "diff --cached"; ds = "diff --staged"; dt = "difftool"; # Add and commit a = "add"; aa = "add -A"; ap = "add -p"; c = "commit"; cm = "commit -m"; ca = "commit -am"; amend = "commit --amend"; # Checkout and branch co = "checkout"; cb = "checkout -b"; br = "branch"; bra = "branch -a"; bd = "branch -d"; bdd = "branch -D"; # Remote r = "remote"; rv = "remote -v"; # Push and pull p = "push"; pf = "push --force-with-lease"; pu = "push -u origin"; pl = "pull"; pom = "push origin main"; plom = "pull origin main"; # Reset and clean unstage = "reset HEAD --"; undo = "reset --soft HEAD~1"; undohard = "reset --hard HEAD~1"; clean-branches = "!git branch --merged | grep -v '\\*\\|master\\|main\\|develop' | xargs -n 1 git branch -d"; # Stash ss = "stash save"; sp = "stash pop"; sl = "stash list"; sd = "stash drop"; # Tags tags = "tag -l"; # Show show-files = "show --pretty=\"\" --name-only"; # Worktree wt = "worktree"; # Maintenance cleanup = "!git remote prune origin && git gc && git clean -df && git stash clear"; # Find find = "!git ls-files | grep -i"; grep = "grep -Ii"; # Contributors contributors = "shortlog --summary --numbered --email"; # Current branch current = "rev-parse --abbrev-ref HEAD"; # Ignore ignore = "!gi() { curl -sL https://www.toptal.com/developers/gitignore/api/$@ ;}; gi"; }; # Global gitignore ignores = [ # OS generated files ".DS_Store" ".DS_Store?" "._*" ".Spotlight-V100" ".Trashes" "ehthumbs.db" "Thumbs.db" # Editor files "*.swp" "*.swo" "*~" ".idea/" # Logs "*.log" # Runtime data "pids" "*.pid" "*.seed" "*.pid.lock" # Coverage directory used by tools like istanbul "coverage/" # Dependency directories "node_modules/" # Optional npm cache directory ".npm" # Optional REPL history ".node_repl_history" # Environment variables ".env.local" ".env.*.local" # Temporary folders "tmp/" "temp/" ]; }; # Delta for better git diffs programs.git.delta = { enable = true; options = { features = "decorations"; syntax-theme = "Dracula"; plus-style = "syntax #003800"; minus-style = "syntax #3f0001"; navigate = true; light = false; line-numbers = true; side-by-side = false; hunk-header-decoration-style = "blue box"; hunk-header-file-style = "red"; hunk-header-line-number-style = "#067a00"; hunk-header-style = "file line-number syntax"; }; }; # Git hooks (if you want to add any) # home.file.".config/git/hooks" = { # source = ./git-hooks; # recursive = true; # }; }