-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup_git.py
executable file
·152 lines (126 loc) · 4.08 KB
/
setup_git.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/usr/bin/env python
import argparse
import os
import pathlib
import subprocess
type torun = dict[str, set[any]]
def run(d: torun):
keys = sorted(d.keys())
for k in keys:
print(f"Adding {k}")
arg_list = sorted(d[k])
for args in arg_list:
args = list(args)
print(" " + " ".join(args))
subprocess.check_call(args=args)
def add_cmds(d: torun, base: str, **defs: str):
for k, v in defs.items():
if v != "":
k = k.replace("_", "-")
args = (
"git",
"config",
"--global",
f"{base}.{k}",
v,
)
d.setdefault(base, set()).add(args)
def setup(d: torun, email: str, signingKey: str, rewrites: dict[str, str]):
t = "true"
f = "false"
add_cmds(d, "apply", whitespace="strip")
add_cmds(d, "branch", sort="-committerdate")
add_cmds(d, "commit", gpgSign=str(signingKey != "").lower(), rebase=t)
add_cmds(d, "core", autocrlf=f, editor="nvim", pager="delta")
add_cmds(d, "difftool", prompt="false")
add_cmds(d, "difftool.difftastic", cmd='difft "$LOCAL" "$REMOTE"')
add_cmds(d, "fetch", prune=t)
add_cmds(d, "init", defaultBranch="main")
add_cmds(d, "interactive", diffFilter="delta --color-only --features=interactive")
add_cmds(d, "log", date="iso")
add_cmds(d, "merge", conflictstyle="zdiff3", keepbackup=f, tool="nvim")
add_cmds(d, "pager", difftool=t)
add_cmds(d, "pull", rebase=f)
add_cmds(d, "push", default="current", followTags=t)
add_cmds(d, "rebase", autosquash=t, autostash=t, updateRefs=t)
add_cmds(d, "rerere", enabled=t)
add_cmds(d, "submodule", recurse=t)
add_cmds(d, "user", name="Adam Lesperance", email=email, signingKey=signingKey)
for b in ["transfer", "fetch", "receive"]:
add_cmds(d, b, fsckobjects=t)
add_cmds(
d,
"alias",
aa="add -A",
ca="commit -a",
co="checkout",
dt="difftool",
dlog="!f() { GIT_EXTERNAL_DIFF=difft git log -p --ext-diff $@; }; f",
gca="gc --aggressive",
st="status",
)
add_cmds(
d,
"cola",
fontdiff="Cascadia Code PL,12,-1,5,50,0,0,0,0,0",
hidpi="1",
icontheme="dark",
spellcheck=f,
startupmode="folder",
theme="flat-dark-blue",
)
add_cmds(
d,
"color",
diff="always",
grep="always",
interactive="always",
pager=t,
status=t,
ui="always",
)
add_cmds(
d,
"delta",
features="decorations",
line_numbers=t,
side_by_side=f,
syntax_theme="Monokai Extended",
)
add_cmds(
d,
"diff",
algorithm="patience",
colorMoved="default",
rename="copy",
tool="difftastic",
)
if rewrites:
add_cmds(d, "url", **rewrites)
def main(email: str, signingKey: str, rewrites: dict[str, str]):
d: torun = dict()
setup(d, email, signingKey, rewrites)
run(d)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Applies global git settings")
parser.add_argument("-e", "--email", default="[email protected]")
parser.add_argument(
"-k", "--key", default="8062DB324D4405D656B07A91E57FA7C8B50DE252"
)
parser.add_argument("--rm", action=argparse.BooleanOptionalAction, default=False)
parser.add_argument("-r", "--rewrite", nargs="*", default=["!github.com"])
args = parser.parse_args()
if args.rm:
(pathlib.Path.home() / ".gitconfig").unlink(missing_ok=True)
rewrites = {}
if args.rewrite is not None:
for urll in args.rewrite:
for url in urll.split(","):
if url != "":
if url.startswith("!"):
action = "pushInsteadOf"
url = url[1:]
else:
action = "insteadOf"
rewrites[f"ssh://git@{url}/.{action}"] = f"https://{url}/"
main(args.email, args.key, rewrites)