-
Notifications
You must be signed in to change notification settings - Fork 0
/
githelpers
45 lines (34 loc) · 1012 Bytes
/
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
#!/bin/bash
HASH="%C(yellow)%h%C(reset)"
RELATIVE_TIME="%C(green)%ar%C(reset)"
AUTHOR="%C(bold blue)%an%C(reset)"
REFS="%C(red)%d%C(reset)"
SUBJECT="%s%C(reset)"
FORMAT="$HASH{$RELATIVE_TIME{$AUTHOR{$REFS $SUBJECT"
function pretty_git_log() {
git log --graph --pretty="tformat:$FORMAT" $* |
column -t -s '{' |
less -FXRS
}
function github_url() {
local remote="$(git remote -v 2> /dev/null | awk '/^origin.*\(push\)$/ {print $2}')"
[[ "$remote" ]] || return
if [[ "$remote" =~ .+(://|@)(github.+)[:|/](.+)/(.+).git ]]; then
host="${BASH_REMATCH[2]}"
user="${BASH_REMATCH[3]}"
repo="${BASH_REMATCH[4]}"
printf "https://$host/$user/$repo\n"
fi
}
function pretty_github_log() {
local url=$(github_url)
echo $url
git log --graph --pretty="tformat:$FORMAT" $* |
awk "$(cat <<AWK
BEGIN { FS = "{"; }
/(.*\{.*)/ { sha=\$1; sub(/.*33m/, "", sha); printf "%s{$url/commit/%s\n", \$0, sha; next }
/.*/ {print \$0}
AWK)" |
column -t -s '{' |
less -FXRS
}