-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.githelpers
72 lines (63 loc) · 1.92 KB
/
.githelpers
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
#!/bin/bash
# Should be in ~/.githelpers and its used it gitconfig
# Log output:
#
# * 51c333e (12 days) <Gary Bernhardt> add vim-eunuch
#
# The time massaging regexes start with ^[^<]* because that ensures that they
# only operate before the first "<". That "<" will be the beginning of the
# author name, ensuring that we don't destroy anything in the commit message
# that looks like time.
#
# The log format uses } characters between each field, and `column` is later
# used to split on them. A } in the commit subject or any other field will
# break this.
filter1() {
if [[ "$platform" == 'macosx' ]]; then
sed -Ee 's/(^[^<]*) ago)/\1)/'
else
ruby -e 'puts $stdin.read.gsub(/(^[^<]*) ago\)/, "\\1)")'
fi
}
filter2() {
if [[ "$platform" == 'macosx' ]]; then
sed -Ee 's/(^[^<]*), [[:digit:]]+ .*months?)/\1)/'
else
ruby -e 'puts $stdin.read.gsub(/(^[^<]*), [[:digit:]]+ .*months?\)/, "\\1)")'
fi
}
platform='unknown'
unamestr=`uname`
if [[ "$unamestr" == 'Linux' ]]; then
platform='linux'
elif [[ "$unamestr" == 'Darwin' ]]; then
platform='macosx'
fi
if [[ "$platform" == 'macosx' ]]; then
#colorized output (because column is aware of escape codes)
HASH="%C(yellow)%h%Creset"
RELATIVE_TIME="%Cgreen(%ar)%Creset"
AUTHOR="%C(bold blue)<%an>%Creset"
REFS="%C(red)%d%Creset"
SUBJECT="%s"
else
# dont use colors as column in linux doesn support escape codes
HASH="%h"
RELATIVE_TIME="(%ar)"
AUTHOR="<%an>"
REFS="%d"
SUBJECT="%s"
fi
FORMAT="$HASH}$RELATIVE_TIME}$AUTHOR}$REFS $SUBJECT"
show_git_head() {
pretty_git_log -1
git show -p --pretty="tformat:"
}
pretty_git_log() {
git log --graph --pretty="tformat:${FORMAT}" $* |
iconv -c -t UTF-8 | # drop invalid UTF-8 characters
filter1 | # Replace (2 years ago) with (2 years)
filter2 | # Replace (2 years, 5 months) with (2 years)
column -s '}' -t | # Line columns up based on } delimiter
less -FXRS # Page only if we need to
}