diff options
author | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-05-25 17:59:54 +0200 |
---|---|---|
committer | Benedikt Peetz <benedikt.peetz@b-peetz.de> | 2024-05-25 17:59:54 +0200 |
commit | 85af021dd76d61b2b05d603b697d18f09e084ff5 (patch) | |
tree | f5b0328d22d011009a7d558a408ba5fde2d600c2 /modules/home/conf/git | |
parent | style(treewide): Format (diff) | |
download | nixos-config-85af021dd76d61b2b05d603b697d18f09e084ff5.tar.gz nixos-config-85af021dd76d61b2b05d603b697d18f09e084ff5.zip |
refactor(git): Move aliases to their own file
Diffstat (limited to '')
-rw-r--r-- | modules/home/conf/git/aliases.nix | 79 | ||||
-rw-r--r-- | modules/home/conf/git/default.nix | 85 |
2 files changed, 80 insertions, 84 deletions
diff --git a/modules/home/conf/git/aliases.nix b/modules/home/conf/git/aliases.nix new file mode 100644 index 00000000..4461e31c --- /dev/null +++ b/modules/home/conf/git/aliases.nix @@ -0,0 +1,79 @@ +{lib}: { + cmr = "commit --file .git/COMMIT_EDITMSG --edit --verbose"; + + st = "status"; + sts = "status --short --branch"; + + ds = "diff --staged"; + di = "diff"; + rs = "restore --staged"; + + ## Logging: + ls = "log --max-count=10 --color --format=format:'%C(bold red)%h%C(reset) %C(dim bold blue)%s%C(reset) %C(dim white)[%aN] %C(bold red)<%G?>%C(reset)%C(auto)%d%C(reset)'"; + + # https://stackoverflow.com/a/61487052 + lg = "lg1"; + lg1 = "lg1-specific --all"; + lg2 = "lg2-specific --all"; + lg3 = "lg3-specific --all"; + + lg1-specific = "log --graph --abbrev-commit --decorate \ + --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold cyan) [%G?]%C(reset)%C(auto)%d%C(reset)'"; + + lg2-specific = "log --graph --abbrev-commit --decorate \ + --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(auto)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)'"; + + lg3-specific = "log --graph --abbrev-commit --decorate \ + --format=format:'%C(bold blue)%h%C(reset)\ + - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)\ + %C(bold cyan)(committed: %cD)%C(reset) %C(auto)%d%C(reset)\ + %C(bold red)(signature: %G? by %GS, trust: %GT)%C(reset)%n\ + '' %C(white)%s%C(reset)%n''\ + %C(dim white)- %an <%ae> %C(reset) %C(dim white)(committer: %cn <%ce>)%C(reset)\ + %C(bold white)- trailers: %(trailers) %C(reset)'"; + + # hard reset with commit before (use reflog to recover) + # git wipe [<commit>] + wipe = lib.strings.concatStringsSep " " [ + "!git" + "add" + "--all" + "&&" + "git" + "commit" + "--quiet" + "--message='WIPE-SAVEPOINT'" + "--no-gpg-sign" + "&&" + "git reset \${1:-HEAD~} --hard" + "&&" + "git clean -fd" + ]; + + branches = lib.strings.concatStringsSep " " [ + "!git" + "for-each-ref" + "--sort=-committerdate" + "--color=always" + "--format='${ + lib.strings.concatStringsSep "|" [ + "%(color:blue)%(authordate:relative)" + "%(color:red)%(authorname)" + "%(color:green)%(color:bold)%(refname:short)" + ] + }'" + "refs/remotes" + "|" + "column -ts'|' -o ' '" + ]; + + tags = "tag --list"; + + remotes = "remote --verbose"; + + day = "!git log --stat --since '1 day ago' --author $(git config user.email)"; + + unpush = "push --force-with-lease origin HEAD~1:${config.programs.git.extraConfig.init.defaultBranch}"; + + wip = "!git add . && git commit --amend && git push --force-with-lease"; +} diff --git a/modules/home/conf/git/default.nix b/modules/home/conf/git/default.nix index e896b317..8a8e73ff 100644 --- a/modules/home/conf/git/default.nix +++ b/modules/home/conf/git/default.nix @@ -1,5 +1,4 @@ { - nixosConfig, lib, config, sysLib, @@ -8,93 +7,11 @@ }: let gitIgnoreFile = ./git_ignore.git; gitTemplateFile = ./git_template.git; - commit = sysLib.writeShellScript { - name = "commit"; - src = ./scripts/commit.sh; - keepPath = true; - dependencies = with pkgs; [ - git - gnused - ]; - }; in { programs.git = { enable = true; #package = pkgs.gitAndTools.gitFull; # TODO: for git send-email support - aliases = { - cm = "!${commit}/bin/commit"; - cmr = "commit --file .git/COMMIT_EDITMSG --edit --verbose"; - - st = "status"; - sts = "status --short --branch"; - - ds = "diff --staged"; - di = "diff"; - rs = "restore --staged"; - - ## Logging: - ls = "log --max-count=10 --color --format=format:'%C(bold red)%h%C(reset) %C(dim bold blue)%s%C(reset) %C(dim white)[%aN] %C(bold red)<%G?>%C(reset)%C(auto)%d%C(reset)'"; - - # https://stackoverflow.com/a/61487052 - lg = "lg1"; - lg1 = "lg1-specific --all"; - lg2 = "lg2-specific --all"; - lg3 = "lg3-specific --all"; - - lg1-specific = "log --graph --abbrev-commit --decorate \ - --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold cyan) [%G?]%C(reset)%C(auto)%d%C(reset)'"; - - lg2-specific = "log --graph --abbrev-commit --decorate \ - --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(auto)%d%C(reset)%n'' %C(white)%s%C(reset) %C(dim white)- %an%C(reset)'"; - - lg3-specific = "log --graph --abbrev-commit --decorate \ - --format=format:'%C(bold blue)%h%C(reset)\ - - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)\ - %C(bold cyan)(committed: %cD)%C(reset) %C(auto)%d%C(reset)\ - %C(bold red)(signature: %G? by %GS, trust: %GT)%C(reset)%n\ - '' %C(white)%s%C(reset)%n''\ - %C(dim white)- %an <%ae> %C(reset) %C(dim white)(committer: %cn <%ce>)%C(reset)\ - %C(bold white)- trailers: %(trailers) %C(reset)'"; - - # hard reset with commit before (use reflog to recover) - # git wipe [<commit>] - wipe = lib.strings.concatStringsSep " " [ - "!git" - "add" - "--all" - "&&" - "git" - "commit" - "--quiet" - "--message='WIPE-SAVEPOINT'" - "--no-gpg-sign" - "&&" - "git reset \${1:-HEAD~} --hard" - "&&" - "git clean -fd" - ]; - branches = lib.strings.concatStringsSep " " [ - "!git" - "for-each-ref" - "--sort=-committerdate" - "--color=always" - "--format='${ - lib.strings.concatStringsSep "|" [ - "%(color:blue)%(authordate:relative)" - "%(color:red)%(authorname)" - "%(color:green)%(color:bold)%(refname:short)" - ] - }'" - "refs/remotes" - "|" - "column -ts'|' -o ' '" - ]; - tags = "tag --list"; - remotes = "remote --verbose"; - day = "!git log --stat --since '1 day ago' --author $(git config user.email)"; - unpush = "push --force-with-lease origin HEAD~1:${config.programs.git.extraConfig.init.defaultBranch}"; - wip = "!git add . && git commit --amend && git push --force-with-lease"; - }; + aliases = import ./aliases.nix {inherit lib pkgs;}; extraConfig = { core = { excludesFile = "${gitIgnoreFile}"; |