{ pkgs, lib, config, ... }: { home.packages = lib.mkIf config.programs.git.enable [ pkgs.b4 pkgs.delta pkgs.difftastic pkgs.git-absorb pkgs.git-bug pkgs.git-chglog pkgs.git-cliff pkgs.git-crypt pkgs.git-extras pkgs.git-filter-repo #pkgs.git-publish pkgs.git-quick-stats pkgs.gitui #pkgs.radicle-node pkgs.tig ]; programs.git = { enable = lib.mkDefault true; ignores = [ "*~" "*.swp" ]; package = lib.mkDefault pkgs.gitMinimal; aliases = { a = "add"; ab = "absorb"; abr = "absorb -r"; ap = "add -p"; au = "add -u"; authors = "shortlog -s -n"; b = "branch"; bl = "git log -p -M --follow --stat --"; c = "commit"; ca = "commit --amend"; caa = "commit --amend -C@"; caaa = "commit --amend -C@ -a"; cf = "commit --fixup"; co = "checkout"; d = "diff"; dc = "diff --cached"; dcw = "diff --cached --word-diff=color"; dh = "diff --histogram"; dp = "diff --patience"; dt = "difftool --patience"; dtc = "difftool --cached"; dw = "diff --word-diff=color"; g = "grep"; ign = "ls-files -o -i --exclude-standard"; l = "log"; ll = "log --graph --decorate --pretty=oneline --abbrev-commit"; lp = "log -p --pretty=fuller --stat"; lpg = "log -p --pretty=fuller --stat -g"; p = "push -v"; pa = "patch"; patch = "push rad HEAD:refs/patches"; # See https://stackoverflow.com/a/65839129/6741004 pf = "push -v --force-with-lease --force-if-includes"; pl = "pull"; r = "reset"; rh = "reset --hard"; ri = "rebase -i"; rp = "reset -p"; s = "status"; spull = "!git-svn fetch && git-svn rebase"; spush = "!git-svn dcommit"; ss = "status -s"; st = "status -uno"; sw = "switch"; fetch-local = "!git fetch local && git tag -d $(git describe --exact-match 2>/dev/null >/dev/null) && git fetch --tags local"; pull-local = "!git fetch-local && git checkout -B master local/master"; pull-local-old = "!git fetch-local && git checkout HEAD'^' && git branch -f master local/master && git checkout master"; root = ''!git rev-list --parents HEAD | egrep "^[a-f0-9]{40}$"''; has-tag-version = ''!git show-ref --tags -d | grep -qx \"^$(git rev-parse HEAD) refs/tags/v[0-9][0-9][0-9][0-9]\\.[0-9][0-9]\\.[0-9][0-9]\\(\\^{}\\)\\?\"''; tag-version = ''"!git has-tag-version && return; v=$(TZ=UTC date +v%Y-%m-%d) && name=$(git rev-parse --show-toplevel | sed -e 's:^.*/work::') && set -x && git tag -s -m \"$name $v\" $v"''; has-tag-majordate = ''!git show-ref --tags -d | grep -qx \"^$(git rev-parse HEAD) refs/tags/v[0-9]\\+.[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\\(\\^{}\\)\\?\"''; tag-majordate = ''"!git has-tag-majordate && return; name=$(basename $(dirname $(git rev-parse --show-toplevel))); major=$(basename $(git rev-parse --show-toplevel)); version=''${version:-$(TZ=UTC date +\"v$major.%Y%m%d\")} && set -x && git tag -s -m \"$name $version\" $version"''; tag-cabal = ''"!set -x; for cabal in $(git ls-files | grep '.*\\.cabal$'); do name=$(sed -ne 's/^name: *\\(.*\\)/\\1/p' \"$cabal\"); version=$(sed -ne 's/^version: *\\(.*\\)/\\1/p' \"$cabal\"); git tag --merged | grep -Fqx \"$name-$version\" || git tag -f -s -m \"$name v$version\" $name-$version; done"''; cl = "notes --ref=changelog append"; cl-bug = "notes --ref=changelogs/bugs append"; cl-feature = "notes --ref=changelogs/features append"; wip = "for-each-ref --sort='authordate:iso8601' --format=' %(color:green)%(authordate:relative)%09%(color:white)%(refname:short)' refs/heads"; }; extraConfig = { browser.elinks.cmd = "elinks"; color.branch = "auto"; color.diff = "auto"; #color.diff.whitespace = "red reverse"; color.status = "auto"; core.commentChar = "auto"; core.quotepath = "false"; core.whitespace = "fix,-indent-with-non-tab,trailing-space,cr-at-eol"; diff.algorithm = "histogram"; diff.sqldiff.command = "sqldiff"; format.pretty = "oneline"; gui.fontdiff = ''-family "DejaVu Sans Mono" -size 8 -weight normal -slant roman -underline 0 -overstrike 0''; gui.fontui = ''-family "DejaVu Sans" -size 8 -weight normal -slant roman -underline 0 -overstrike 0''; gui.spellingdictionary = "en_US"; gui.tabsize = 4; guitool."Rebase interactive" = { cmd = "EDITOR=gvim git rebase -i $REVISION"; revprompt = true; }; init.defaultBranch = "main"; merge.tool = "vimdiff"; merge.conflictStyle = "zdiff3"; protocol.version = 2; pull.rebase = true; push.default = "simple"; push.useForceIfIncludes = true; rebase.autosquash = "true"; sendemail.chainReplyTo = "false"; sendemail.composeencoding = "UTF-8"; sendemail.confirm = "always"; sendemail.envelopeSender = "auto"; sendemail.multiedit = "yes"; sendemail.suppressFrom = "false"; sendemail.suppresscc = "self"; sendemail.thread = "true"; sendemail.validate = "true"; web.browser = "elinks"; }; iniContent = { /* diff.external = lib.concatStringsSep " " [ "${pkgs.difftastic}/bin/difft" "--color auto" "--background dark" "--display side-by-side" ]; */ # difftastic /* diff.tool = "difftastic"; difftool.prompt = false; difftool.difftastic.cmd = ''${pkgs.difftastic}/bin/difft "$LOCAL" "$REMOTE"''; pager.difftool = true; */ # delta /* core.pager = "delta --grep-separator-symbol keep"; interactive.diffFilter = "delta --color-only --features=interactive"; delta.features = "decorations"; delta.interactive = { keep-plus-minus-markers = false; }; delta.decorations = { commit-decoration-style = "blue ol"; commit-style = "raw"; file-style = "omit"; hunk-header-decoration-style = "blue box"; hunk-header-file-style = "red"; hunk-header-line-number-style = "#067a00"; hunk-header-style = "file line-number syntax"; }; */ }; }; programs.bash = lib.mkIf config.programs.git.enable { shellAliases = { g = "git"; ge = "git-edit-commit"; gg = "git grep"; gge = "git-grep-edit"; gui = "gitui"; }; initExtra = '' git-edit-commit () { $EDITOR $(git diff-tree --no-commit-id --name-only -r "$@"); } git-grep-edit () { $EDITOR $(git grep --name-only --recursive "$@"); } ''; }; }