-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy path.githelpers
61 lines (53 loc) · 1.8 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
#!/usr/bin/env bash
# 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.
HASH="%C(yellow)%h%Creset"
RELATIVE_TIME="%Cgreen(%ar)%Creset"
AUTHOR="%C(bold blue)<%an>%Creset"
REFS="%C(red)%d%Creset"
SUBJECT="%s"
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 --color --pretty="tformat:${FORMAT}" $* |
# Replace (2 years ago) with (2 years)
sed -Ee 's/(^[^<]*) ago\)/\1)/' |
# Replace (2 years, 5 months) with (2 years)
sed -Ee 's/(^[^<]*), [[:digit:]]+ .*months?\)/\1)/' |
# Line columns up based on } delimiter
column -s '}' -t |
# Page only if we need to
less -FXRS
}
prune_and_delete_merged() {
git checkout main
git pull --rebase
git remote prune origin
git branch --merged | grep -v "\*" | xargs -n 1 git branch -d
}
clean_local() {
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [ "$BRANCH" != "main" ]; then
read -p "Are you sure you want to run while not in main (you run the risk of deleting main)? (y/n) " choice
if [ "$choice" != "Y" ] && [ "$choice" != "y" ]; then
echo "Nothing done"
exit 0
fi
fi
for stale_branch in $(git branch --merged $BRANCH | grep -v $BRANCH); do
git branch -d $stale_branch
done
}