-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathgitconfig
501 lines (461 loc) · 22 KB
/
gitconfig
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
[user]
name = Jeff Wu
email = [email protected]
[core]
# editor = vim -V9/tmp/myVim.log
editor = nvim
# pager = "if which icdiff > /dev/null; then PAG='git difftool --no-prompt --extcmd=\"icdiff\"'; else PAG='less'; fi; $PAG"
pager = "if which delta > /dev/null; then PAG='delta -s'; else PAG='less'; fi; $PAG"
excludesfile = ~/.gitignore_global
# [interactive]
# diffFilter = delta --color-only -s
[delta]
navigate = true # use n and N to move between diff sections
# syntax-theme = zenburn
minus-style = "#eeaaaa" bold "#440000"
minus-emph-style = "#eeaaaa" bold "#440000"
minus-non-emph-style = "#eeaa88" bold "#444422"
plus-style = "#aaeeaa" bold "#004400"
plus-emph-style = "#aaeeaa" bold "#004400"
plus-non-emph-style = "#aaee88" bold "#444422"
[alias]
# TODO: DIFF TOOL, ACTUALLY MAYBE ... https://difftastic.wilfred.me.uk/git.html
# https://github.com/jeffkaufman/icdiff
# configuration
# icdiff = "!f() { git difftool --no-prompt --extcmd=\"icdiff $(git config --get icdiff.options)\" \"$@\" | less -R; }; f"
# differ = "!f() { if which icdiff > /dev/null; then echo icdiff; else echo diff; fi; }; f"
main = "!f() { if git rev-parse --verify main >/dev/null 2>&1; then echo main; else echo master; fi; }; f"
delta = "!f() { git diff \"$@\" | delta -s; }; f"
differ = "!f() { if which delta > /dev/null; then echo delta; else echo diff; fi; }; f"
# editor = config --get core.editor
editor = "!f() { if [ \"$ZED_TERM\" = \"true\" ]; then echo "zed -p"; else echo $(git config --get core.editor); fi; }; f"
# editor = ! echo "emacsclient -c"
alias = "!f() { pattern=$@; git config --get-regexp ^alias\\. | sed -e s/^alias\\.// -e 's/ / = /' | awk -v pat=\"$pattern\" '{ if ($0 ~ pat) print }' | sort -u; }; f"
which = "!f() { pattern=$@; git config --get-regexp ^alias\\. | sed -e s/^alias\\.// -e 's/ / = /' | awk -v pat=\"$pattern\" -F '=' '{ if ($1 ~ pat) print $0 }' | sort -u; }; f"
linecount = "!f() { git ls-files $@ | grep -v package-lock.json | grep -v Pipfile.lock | xargs cat | wc -l; }; f"
linecounts = "!f() { for f in $(git ls-files $@ | grep -v package-lock.json | grep -v Pipfile.lock); do echo $(wc -l $f); done; }; f"
# utils
root = rev-parse --show-toplevel
# executes command at git root
rooted = "!git"
# functions screw up directory: see https://stackoverflow.com/questions/26243145/git-aliases-operate-in-the-wrong-directory
relative = "!f() { if [ -n \"$GIT_PREFIX\" ]; then echo \"$GIT_PREFIX\"; else echo \".\"; fi; }; f"
# chains multiple commands (note: after first one, can't have spaces, for now)
chain = "!f() { if [ -n \"$GIT_PREFIX\" ]; then cd \"$GIT_PREFIX\"; fi; if [ $# -eq 0 ]; then return 0; fi; git $1; shift; git chain $@; }; f"
# setup
clo = clone --recursive
in = '!git init && git commit -m "root" --allow-empty'
# https://github.com/$1.git
# [email protected]:$1.git
# branch management
b = branch -vv --sort=committerdate
bb = rev-parse --abbrev-ref HEAD
# bb = branch --show-current # works in newer version of git
ba = branch -vv -a
co = checkout
com = "!f() { git checkout $(git main) $@; }; f"
cop = checkout -p
new = checkout -b
bd = branch -D
bdm = "!git branch --merged | grep -v '\\*' | xargs -n 1 git branch -d"
# delete a branch (default to current branch). if current branch deleted, checkout main
bx = "!f() { \
local onbranch=$(git bb); \
local branch=${1:-$onbranch}; \
local mainbranch=$(git main); \
if [ \"$branch\" = \"$mainbranch\" ]; then \
echo \"Can't delete $mainbranch!\"; \
return 1; \
fi; \
if [ \"$branch\" = \"$onbranch\" ]; then \
git checkout $mainbranch; \
fi && \
git tag -f shelved/$branch $branch && \
git branch -D $branch; \
}; f"
# delete remote branch
bxr = "!f() { \
local onbranch=$(git bb); \
local branch=${1:-$onbranch}; \
git push origin :$branch; \
}; f"
# Remove branches that have already been merged with main, a.k.a. ‘delete merged’
done = "!f() { \
local mybranch=$(git bb); \
local mainbranch=$(git main); \
if [ \"$mybranch\" != \"$mainbranch\" ]; then git checkout $mainbranch; git reset --hard $mybranch; fi; \
git fetch; git rebase origin/$mainbranch; git push origin $mainbranch; \
if [ \"$mybranch\" != \"$mainbranch\" ]; then git branch -D $mybranch; git push origin :$mybranch; fi; \
}; f"
rmc = "rm --cached"
# remotes
# f = "!f() { git chain 'fetch --all --prune' $@; }; f"
f = "!f() { \
if [ \"$(git root)\" = \"$HOME/openai/openai\" ]; then \
git fetch origin "refs/heads/${OPENAI_USER}*:refs/remotes/origin/${OPENAI_USER}*"; \
git fetch origin master; \
git chain $@; \
else \
git chain 'fetch --all --prune' $@; \
fi; \
}; f"
pu = "push -u"
put = "push --tags"
puf = "push -u --force-with-lease"
pufback = "!f() { local nback=${1:-1}; git puf origin HEAD~${nback}:$(git b --show-current); }; f"
pl = "pull"
plr = "pull --rebase"
pla = "!f() { git pull; git submodule foreach git pull origin $(git main); }; f"
rmp = "!f(){ remote=${1:-origin}; git remote prune $remote; }; f"
track = "!f(){ branch=$(git bb); cmd=\"git branch $branch -u ${1:-origin}/${2:-$branch}\"; echo $cmd; $cmd; }; f"
untrack = "!f(){ branch=$(git bb); cmd=\"git branch --unset-upstream ${1:-$branch}\"; echo $cmd; $cmd; }; f"
# todo: get autocomplete for this
# todo: get better prompt
# i = !repl git
i = "!f(){ \
while true; do \
read -e -p \"git $ \" line; \
if [ -z \"$line\" ]; then continue; fi; \
if [ \"$line\" == \"q\" ]; then break; fi; \
if [ \"${line:0:1}\" == \"!\" ]; then \
eval \"${line:1}\"; \
else \
eval \"git $line\"; \
fi; \
done }; f"
remoteuser = "!f() { \
remote=${1:-origin}; \
git_remote=$(git remote -v | head -n 1 | cut -f 2 -d ':'); \
echo $(git remote get-url $remote | cut -f 2 -d ':' | cut -f 1 -d '/'); \
}; f"
remoterepo = "!f() { \
remote=${1:-origin}; \
git_remote=$(git remote -v | head -n 1 | cut -f 2 -d ':'); \
git_repo=$(git remote get-url $remote | cut -f 2 -d ':' | cut -f 2 -d '/'); \
git_repo=${git_repo::$((${#git_repo}-4))}; \
echo $git_repo; \
}; f"
# github
pr = "!git push; hub pull-request"
# pr = "!f() { \
# local remote=${1:-origin}; \
# local mainbranch=$(git main); \
# git push; \
# git_user=$(git remoteuser); \
# git_repo=$(git remoterepo); \
# cur_branch=$(git bb); \
# echo open \"https://github.com/$git_user/$git_repo/compare/$mainbranch...$cur_branch\"; \
# # open \"https://github.com/$git_user/$git_repo/pull/create?base=$git_user%3A$mainbranch&head=$git_user%3A$cur_branch\"; \n\
# open \"https://github.com/$git_user/$git_repo/compare/$mainbranch...$cur_branch\"; \
# }; f"
try = "!f() { \
if [ -n \"$GIT_PREFIX\" ]; then cd \"$GIT_PREFIX\"; fi; \
while ! git $@; do sleep 1; done; \
}; f"
prm = "!f() { \
local remote=${1-origin}; \
local branch=${2:-$(git bb)}; \
local merge_method=${3:-merge}; \
local GITHUB_TOKEN=$(cat ~/.github_token); \
local user=$(git remoteuser $remote); \
local repo=$(git remoterepo $remote); \
echo https://api.github.com/repos/$user/$repo/pulls; \
prnum=$(curl -s -X GET -H \"Authorization: token $GITHUB_TOKEN\" https://api.github.com/repos/$user/$repo/pulls | jq '.[] | select(.head.ref==\"'$branch'\") | .number'); \
echo https://api.github.com/repos/$user/$repo/pulls/$prnum/merge; \
curl -s -X PUT -H \"Authorization: token $GITHUB_TOKEN\" -d '{\"merge_method\": \"'$merge_method'\"}' https://api.github.com/repos/$user/$repo/pulls/$prnum/merge | tee /dev/tty | grep '\"merged\": true'; \
exit $?; \
}; f"
prr = "!f() { local remote=${1:-origin}; local branch=${2:-$(git bb)}; git prm $remote $branch rebase; }; f"
prs = "!f() { local remote=${1:-origin}; local branch=${2:-$(git bb)}; git prm $remote $branch squash; }; f"
trypr = "!f() { \
local remote=${1-origin}; \
local branch=${2:-$(git bb)}; \
local mainbranch=$(git main); \
local merge_method=${3:-rebase}; \
git try prm $remote $branch $merge_method; \
if [ \"$branch\" != \"$mainbranch\" ]; then \
if [ \"$branch\" == \"$(git bb)\" ]; then \
git checkout $mainbranch; \
fi; \
git branch -D $branch; git push origin :$branch; \
fi; \
}; f"
donepr = "!f() { \
local remote=${1-origin}; \
local mybranch=${2:-$(git bb)}; \
local mainbranch=$(git main); \
local merge_method=${3:-rebase}; \
git prm $remote $mybranch $merge_method || echo fail to merge && exit 1; \
if [ \"$mybranch\" != \"$mainbranch\" ]; then git checkout $mainbranch; git branch -D $mybranch; git push origin :$mybranch; fi; \
}; f"
doneprr = "!f() { local remote=${1:-origin}; git donepr $remote rebase; }; f"
doneprs = "!f() { local remote=${1:-origin}; git donepr $remote squash; }; f"
h = "!f() { hash=${1:-$(git bb)}; hub browse -- tree/$hash; }; f"
hi = "!hub browse -- issues"
hin = "!hub browse -- issues/new"
hp = "!f() { pr=$1; if [ -z \"$1\" ]; then hub browse -- pulls; else hub browse -- pull/$pr ; fi; }; f"
hf = "!f() { local mainbranch=$(git main); hub browse -- find/$mainbranch; }; f"
hop = "!f() { local mainbranch=$(git main); hub browse -- blob/$mainbranch/$(git find \"$@\" | head -n 1); }; f"
# hub log
hl = "!f() { hash=${1:-$(git rev-parse HEAD)}; hub browse -- commits/$hash; }; f"
# hub show
hs = "!f() { hash=${1:-$(git rev-parse HEAD)}; hub browse -- commit/$hash; }; f"
issue = "!hub issue"
fork = "!hub fork"
# working tree
a = add
aahelper = "!git add .; git add -u ."
aa = "!f() { git chain 'aahelper' $@; }; f"
aac = "!f() { git aahelper; git ac $@; }; f"
ap = "!f() { if [ -n \"$GIT_PREFIX\" ]; then cd \"$GIT_PREFIX\"; fi; local dir=${1:-.}; git add -p $dir; }; f"
# cleanup
cle = clean -f -d
# discard
xx = "!f() { if [ -n \"$GIT_PREFIX\" ]; then cd \"$GIT_PREFIX\"; fi; local dir=${1:-.}; git checkout -- $dir; }; f"
# unstage
z = "!f(){ if [ -n \"$GIT_PREFIX\" ]; then cd \"$GIT_PREFIX\"; fi; local dir=${1:-.}; git reset HEAD $dir; }; f"
# committing (optionally with message)
c = "!f() { if [ $# -eq 0 ]; then git commit -v; else git commit -m \"$*\"; fi; }; f"
# commit "squash"
cs = "!f() { if [ $# -eq 0 ]; then git commit -v --amend; else git commit --amend -m \"$*\"; fi; }; f"
# commit "fixup"
cf = commit -v --amend --no-edit
# add then commit variants
ac = "!f() { if [ $# -eq 0 ]; then git commit -v -a; else git commit -a -m \"$*\"; fi; }; f"
acs = "!f() { if [ $# -eq 0 ]; then git commit -v -a --amend; else git commit -a --amend -m \"$*\"; fi; }; f"
acf = "!f() { git chain 'commit -v -a --amend --no-edit' $@; }; f"
# cherry-pick
cp = cherry-pick
cpa = cherry-pick --abort
cpc = cherry-pick --continue
# rebase
rb = rebase
rbi = rebase -i
rbin = "!f() { local n=${1:-1}; git rebase -i HEAD~$n; }; f"
rba = rebase --abort
rbs = rebase --skip
rbc = "!git add .; git add -u .; git rebase --continue"
rbo = "!f(){ local branch=$(git bb); git rebase origin/$branch $@; }; f"
rboi = "!f(){ local branch=$(git bb); git rebase origin/$branch -i $@; }; f"
rbm = "!f(){ local mainbranch=$(git main); git rebase $mainbranch $@; }; f"
rbmi = rbm -i
rbom = "!f(){ local mainbranch=$(git main); git rebase origin/$mainbranch $@; }; f"
rbomi = rbom -i
from = "!f() { git chain f rbom $@; }; f"
fro = "!f() { git chain f rbo $@; }; f"
# merge
m = merge
ma = merge --abort
# open merge conflicts (good for rebase/cherry-pick/merge too)
mop = "!f() { $(git editor) $(git diff --name-only --diff-filter=U); }; f"
# diffs
d = "!f() { if [ -n \"$GIT_PREFIX\" ]; then cd \"$GIT_PREFIX\"; fi; git $(git differ) $@; }; f"
dc = "!f() { if [ -n \"$GIT_PREFIX\" ]; then cd \"$GIT_PREFIX\"; fi; git $(git differ) --cached $@; }; f"
dcs = "!git --no-pager -c color.diff=always diff --stat --cached"
ds = "!git --no-pager -c color.diff=always diff --stat"
dso = "!f(){ local branch=$(git bb); git diff --stat origin/$branch $@; }; f"
dsop = "!f() { $(git editor) $(git --no-pager -c color.diff=always diff --stat --name-only $1); }; f"
dsom = "!f() { local mainbranch=$(git main); git --no-pager -c color.diff=always diff --stat origin/$mainbranch;}; f"
dsm = "!f() { local mainbranch=$(git main); git --no-pager -c color.diff=always diff --stat $mainbranch;}; f"
df = "!f() { git diff --name-only $@; }; f"
dfom = "!f() { local mainbranch=$(git main); git diff --name-only origin/$mainbranch; }; f"
dcf = "!f() { git diff --cached --name-only $@; }; f"
dop = "!f() { $(git editor) $(git df); }; f"
dcop = "!f() { $(git editor) $(git diff --cached --name-only $@); }; f"
dm = "!f(){ local mainbranch=$(git main); if [ -n \"$GIT_PREFIX\" ]; then cd \"$GIT_PREFIX\"; fi; git $(git differ) $mainbranch; }; f"
dom = "!f(){ local mainbranch=$(git main); if [ -n \"$GIT_PREFIX\" ]; then cd \"$GIT_PREFIX\"; fi; git $(git differ) origin/$mainbranch; }; f"
do = "!f(){ if [ -n \"$GIT_PREFIX\" ]; then cd \"$GIT_PREFIX\"; fi; local branch=$(git bb); git $(git differ) origin/$branch $@; }; f"
du = "!git $(git differ) @{upstream}"
# status
s = "!f() { if [ -n \"$GIT_PREFIX\" ]; then cd \"$GIT_PREFIX\"; fi; git chain 'status' $@; }; f"
sh = show
sho = "!f(){ local branch=$(git bb); git show origin/$branch $@; }; f"
shom = "!f() { local mainbranch=$(git main); git show origin/$mainbranch; }; f"
shs = "!git --no-pager show --stat"
shso = "!f(){ local branch=$(git bb); git --no-pager show --stat origin/$branch $@; }; f"
shsom = "!f() { local mainbranch=$(git main); git --no-pager show --stat origin/$mainbranch; }; f"
shop = "!f() { $(git editor) $(git show --pretty=\"format:\" --name-only $1); }; f"
# tree
l = log --color --graph --pretty='%C(yellow)%h%C(reset) %Cred%cd%C(reset) %C(bold blue)%an%C(reset) %s%C(bold yellow)%d%C(reset)' --decorate --date=relative
ls = log --color --pretty=format:'%C(yellow)%h%C(reset) %Cred%cd%C(reset) %C(bold blue)%an%C(reset) %s%C(bold yellow)%d%C(reset)' --decorate --date=relative --numstat
lo = "!f(){ local branch=$(git bb); git log origin/$branch $@; }; f"
lom = "!f() { local mainbranch=$(git main); git log origin/$mainbranch; }; f"
lg = log
hash = rev-parse HEAD
shash = rev-parse --short HEAD
rl = reflog show --date=relative
# file tools
find = "!f() { if [ -n \"$GIT_PREFIX\" ]; then cd \"$GIT_PREFIX\"; fi; git ls-files | grep -i $@; }; f"
op = "!f() { \
if [ -n \"$GIT_PREFIX\" ]; then cd \"$GIT_PREFIX\"; fi; \
files=$(git ls-files | grep -i \"$@\"); \
if [ -n \"$files\" ]; then \
$(git editor) $files; \
else \
echo \"No files to open matching pattern: $@\"; \
fi; \
}; f"
# open edited
eop = "! $(git editor) $(git ls-files --modified)"
g = "!f() { if [ -n \"$GIT_PREFIX\" ]; then cd \"$GIT_PREFIX\"; fi; git --no-pager grep \"$1\" $2; }; f"
gi = "!f() { if [ -n \"$GIT_PREFIX\" ]; then cd \"$GIT_PREFIX\"; fi; git --no-pager grep -i \"$1\" $2; }; f"
# grep and open
gop = "!f(){ if [ -n \"$GIT_PREFIX\" ]; then cd \"$GIT_PREFIX\"; fi; $(git editor) $(git grep --name-only \"$1\" $2); }; f"
giop = "!f(){ if [ -n \"$GIT_PREFIX\" ]; then cd \"$GIT_PREFIX\"; fi; $(git editor) $(git grep -i --name-only \"$1\" $2); }; f"
# only works with vim for now (uses format `+lineno file`), and no multi-select
# could make it work though! needs e.g. vim-fetch, fzf -m, and cut -d \":\" -f 1-3 instead of awk (`file:lineno:lineno` format)
zg = "!f() { \
rg --color=always --column --line-number --no-heading . | fzf --ansi --delimiter : --preview 'bat --theme=$(defaults read -globalDomain AppleInterfaceStyle &> /dev/null && echo default || echo GitHub) --color=always {1} --highlight-line {2}' --preview-window 'up,60%,border-bottom,+{2}+3/3,~3' | awk -F: '{ printf \"%s +%s\\n\", $1, $2 }' | xargs $(git editor);\
}; f"
tree = ls-tree -r HEAD
# reset
rs = reset
rso = "!f(){ local branch=$(git bb); git reset origin/$branch $@; }; f"
rsm = "!git reset $(git main)"
rsom = "!git reset origin/$(git main)"
rsh = reset --hard
rsho = "!f(){ local branch=$(git bb); git reset --hard origin/$branch $@; }; f"
rshom = "!git reset --hard origin/$(git main)"
rshm = "!git reset --hard $(git main)"
# rewind
rw = "!f() { local n=${1:-1}; git reset HEAD~$n; }; f"
rwh = "!f() { local n=${1:-1}; git reset --hard HEAD~$n; }; f"
# revert
rv = "!f() { local hash=${1:-HEAD}; git revert $hash; }; f"
rva = revert --abort
rvc = revert --continue
# stash
# TODO: reimplement this using branches
# $ git config --global alias.stsh 'stash --keep-index'
# git config --global alias.staash 'stash --include-untracked'
# git config --global alias.staaash 'stash --all'
st = "!f() { git chain stash $@; }; f"
stl = stash list
sta = stash apply
std = stash drop
sts = stash save
stp = stash pop
# tags
t = tag
td = tag -d
# bisection
bs = bisect
bsb = bisect bad
bsg = bisect good
bsr = bisect reset
bss = bisect start
# submodules
smi = submodule init
sma = submodule add
smu = submodule update
sms = submodule sync
# fuzzy commands (require fzf)
# get commit hash
zh = "!f() { \
local target=$1; \
local commit=\"\"; \
if fzf --help 2>&1 | grep --quiet '\\-\\-ansi'; then \
commit=$(git l $target | fzf --preview 'git --no-pager show --color {2}' --ansi | sed 's/.*\\*[^ ]*//g' | awk '{ print $1 }'); \
else \
commit=$(git log --color --graph --pretty='%h %cd %an %s%d' --decorate --date=relative $target | fzf --preview 'git --no-pager show --color {2}' | cut -d '*' -f 2 | awk '{ print $1 }'); \
fi; \
echo \"$commit\"; \
}; f"
# get file
zf = "!f() { \
local file=$(git ls-files $(git rev-parse --show-toplevel) | fzf -m --preview 'cat {1}'); \
if [[ -z $file ]]; then return 1; fi; \
echo \"$file\"; \
}; f"
# get branch
# consider: g branch -a --format '%(refname); \
zb = "!f() { \
local branch=$(git branch -a --sort=-committerdate | grep -v 'remotes/' | fzf -m --preview 'git l {1}'); \
if [[ -z $branch ]]; then return 1; fi; \
echo \"$branch\"; \
}; f"
zba = "!f() { \
local branch=$(git branch -a --sort=-committerdate | fzf -m --preview 'git l {1}'); \
if [[ -z $branch ]]; then return 1; fi; \
echo \"$branch\"; \
}; f"
# fuzzy open
zop = "!f() { \
local file=$(git zf); \
if [[ -z $file ]]; then return 1; fi; \
$(git editor) $file; \
echo $(git editor) $file; \
}; f"
# fuzzy grep (does only one file)
zgop = "!f() { rg --color ansi --vimgrep $@ | fzf --ansi --preview '~/.preview.sh {}' | pyp 'z = x.split(\":\"); print(f\"+{z[1]} -c \\\"normal {z[2]}|\\\" {shlex.quote(z[0])}\")' | xargs -o vim; }; f"
# fuzzy checkout (could be much improved, have tags, branches, remotes)
zc = "!f() { \
local branch=$(git zb); \
if [[ -z $branch ]]; then return 1; fi; \
git checkout $branch; \
echo git checkout $branch; \
}; f"
zch = "!f() { \
local commit=$(git zh); \
if [[ -z $commit ]]; then return 1; fi; \
git checkout $commit; \
echo git checkout $commit; \
}; f"
# fuzzy show
# see: https://gist.github.com/junegunn/f4fca918e937e6bf5bad
zsh = "!f() { \
git log --graph --color=always --abbrev=7 --format='%C(auto)%h %an %C(blue)%s %C(yellow)%cr' $@ | fzf --ansi --no-sort --reverse --tiebreak=index \
--preview \"f() { set -- \\$(echo -- \\$@ | grep -o '[a-f0-9]\\{7\\}'); [ \\$# -eq 0 ] || git show --color=always \\$1 $filter; }; f {}\" \
--preview-window=right:60% \
--height 80%; \
}; f"
zshs = "!f() { \
git log --graph --color=always --abbrev=7 --format='%C(auto)%h %an %C(blue)%s %C(yellow)%cr' $@ | fzf --ansi --no-sort --reverse --tiebreak=index \
--preview \"f() { set -- \\$(echo -- \\$@ | grep -o '[a-f0-9]\\{7\\}'); [ \\$# -eq 0 ] || git show --color=always --stat \\$1 $filter; }; f {}\" \
--preview-window=right:60% \
--height 80%; \
}; f"
# fuzzy diff
zd = "!f() { \
local commit=$(git zh); \
if [[ -z $commit ]]; then return 1; fi; \
git $(git differ) $commit; \
echo git $(git differ) $commit; \
}; f"
# TODO: make a single command that lists
# commits, tags, branches, remotes
# use in the fuzzy stuff
# miscellaneous
# Find commits by commit message
fc = "!f() { git log --pretty=format:'%C(yellow)%h %Cblue%ad %Creset%s%Cgreen [%cn] %Cred%d' --decorate --date=short --grep=\"$@\"; }; f"
# List contributors with number of commits
contributors = shortlog --summary --numbered
# shelf = "!f() { git tag | grep shelved } ; f"
[color]
# diff = always
ui = true
[push]
default = current
[rerere]
enabled = true
# [branch]
# autosetupmerge = always
# autosetuprebase = always
[merge]
conflictstyle = zdiff3
[rebase]
autosquash = true
autostash = true
[init]
defaultBranch = main
[fetch]
fsckObjects = true
[transfer]
fsckObjects = true
[receive]
fsckObjects = true
[gc]
auto = 256
# [safe]
# directory = /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
# directory = /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask