{ lib, config, pkgs, ... }: let cfg = config.snowhawk.git; macos = config.snowhawk.macos.enable; sshifyPushUrl = let urlParser = "${pkgs.url-parser}/bin/url-parser"; git = "${pkgs.git}/bin/git"; cut = "${pkgs.coreutils}/bin/cut"; in pkgs.writeShellScriptBin "sshify-push-url" '' base=$(${urlParser} --url $(${git} remote get-url origin) host) path=$(${urlParser} --url $(${git} remote get-url origin) path | ${cut} -b 2-) echo "$base:$path" ''; in { options.snowhawk.git = { enable = lib.mkEnableOption "git"; oauth = lib.mkEnableOption "enable git-credential-oauth"; }; config = lib.mkIf cfg.enable { home.packages = lib.mkIf cfg.oauth [ pkgs.git-credential-oauth ]; programs.git = { enable = true; userName = "Zynh Ludwig"; userEmail = "zynh0722@gmail.com"; ignores = [ "Session.vim" (lib.mkIf macos ".DS_Store") ]; aliases = { co = "checkout"; ci = "commit"; st = "status"; br = "branch"; hist = "log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short"; type = "cat-file -t"; dump = "cat-file -p"; graph = "log --graph --decorate --pretty=oneline --abbrev-commit"; # Convert pull url into ssh push url sshify-push-url = '' !${pkgs.bash}/bin/bash -c "git remote set-url --push origin $(${sshifyPushUrl}/bin/sshify-push-url)" ''; # local patch-wise ignore workflow unchanged = "update-index --assume-unchanged"; changed = "update-index --no-assume-unchanged"; show-unchanged = ''!"git ls-files -v | sed -e 's/^[a-z] //p; d'\"''; }; extraConfig = { init.defaultBranch = "main"; core = { editor = "nvim"; autocrlf = "input"; safecrlf = true; }; pull.rebase = true; credential = { helper = [ "cache --timeout 7200" (lib.mkIf cfg.oauth "oauth") ]; "https://git.zynh.me" = { oauthClientId = "13d5b95d-565d-4264-8961-c45cc38eaa8a"; oauthScopes = "read_repository write_repository"; oauthAuthURL = "/login/oauth/authorize"; oauthTokenURL = "/login/oauth/access_token"; }; }; }; }; }; }