1{
2 pkgs,
3 lib,
4 config,
5 ...
6}:
7let
8 cfg = config.py.programs.git;
9in
10{
11 options.py.programs.git = {
12 enable = lib.mkEnableOption "git configuration";
13 lazygit.enable = lib.mkEnableOption "lazygit configuration";
14 gh.enable = lib.mkEnableOption "gh configuration";
15 };
16 config = {
17 catppuccin = {
18 lazygit.enable = cfg.lazygit.enable;
19 };
20 programs = {
21 git = lib.mkIf cfg.enable {
22 enable = true;
23 package = pkgs.git;
24 aliases = {
25 a = "add -p";
26 co = "checkout";
27 cob = "checkout -b";
28 f = "fetch -p";
29 c = "commit";
30 p = "push";
31 ba = "branch -a";
32 bd = "branch -d";
33 bD = "branch -D";
34 d = "diff";
35 dc = "diff --cached";
36 ds = "diff --staged";
37 r = "restore";
38 rs = "restore --staged";
39 st = "status -sb";
40 # reset
41 soft = "reset --soft";
42 hard = "reset --hard";
43 s1ft = "soft HEAD~1";
44 h1rd = "hard HEAD~1";
45 # logging
46 lg = "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit";
47 plog = "log --graph --pretty='format:%C(red)%d%C(reset) %C(yellow)%h%C(reset) %ar %C(green)%aN%C(reset) %s'";
48 tlog = "log --stat --since='1 Day Ago' --graph --pretty=oneline --abbrev-commit --date=relative";
49 rank = "shortlog -sn --no-merges";
50 # delete merged branches
51 bdm = "!git branch --merged | grep -v '*' | xargs -n 1 git branch -d";
52 wt = "worktree";
53 };
54 delta = {
55 enable = true;
56 options.line-numbers = true;
57 };
58 extraConfig = {
59 branch.sort = "-committerdate";
60 column.ui = "auto";
61 core.editor = lib.getExe pkgs.neovim;
62 "credential \"https://git.pyrox.dev\"".username = "pyrox";
63 credential.helper = "rbw";
64 diff = {
65 algorithm = "histogram";
66 colorMoved = "plain";
67 mnemonicPrefix = true;
68 renames = true;
69 };
70 fetch = {
71 all = true;
72 prune = true;
73 pruneTags = true;
74 };
75 gpg.ssh.allowedSignersFile = "~/.ssh/authorized_signatures";
76 init.defaultBranch = "main";
77 pull.rebase = false;
78 push = {
79 autoSetupRemote = true;
80 followTags = true;
81 };
82 rebase.updateRefs = true;
83 tag.sort = "version:refname";
84 };
85 lfs = {
86 enable = true;
87 skipSmudge = false;
88 };
89 signing = {
90 key = "~/.ssh/main.pub";
91 format = "ssh";
92 signByDefault = true;
93 };
94 userEmail = "pyrox@pyrox.dev";
95 userName = "dish";
96 };
97 mergiraf = lib.mkIf cfg.enable {
98 enable = true;
99 };
100 lazygit = lib.mkIf cfg.lazygit.enable {
101 enable = true;
102 settings = {
103 gui = {
104 nerdFontsVersion = "3";
105 showRandomTip = false;
106 theme.selectedLineBgColor = [ "default" ];
107 };
108 git.paging = {
109 pager = "${lib.getExe pkgs.delta} --dark --paging=never";
110 colorArg = "always";
111 };
112 services = {
113 "git.pyrox.dev" = "gitea:git.pyrox.dev";
114 "git.dn42.dev" = "gitea:git.dn42.dev";
115 "codeberg.org" = "gitea:codeberg.org";
116 };
117 };
118 };
119 gh = lib.mkIf cfg.gh.enable {
120 enable = true;
121 gitCredentialHelper.enable = true;
122 settings = {
123 editor = lib.getExe pkgs.neovim;
124 git_protocol = "https";
125 browser = lib.mkIf config.py.profiles.gui.enable pkgs.firefox;
126 prompt = "enabled";
127 };
128 };
129 };
130 };
131}