-
Notifications
You must be signed in to change notification settings - Fork 2
/
.functions
32 lines (29 loc) · 1004 Bytes
/
.functions
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
# add a github remote by github username
function gra() {
if (( "${#@}" != 1 )); then
echo "Usage: gra githubuser"
return 1;
fi
local repo=$(gr show -n origin | perl -ne '/Fetch URL: .*github\.com[:\/].*\/(.*)/ && print $1')
gr add "$1" "git://github.com/$1/$repo"
}
# git log with per-commit cmd-clickable GitHub URLs (iTerm)
function gf() {
local remote="$(git remote -v | awk '/^origin.*\(push\)$/ {print $2}')"
[[ "$remote" ]] || return
local user_repo="$(echo "$remote" | perl -pe 's/.*://;s/\.git$//')"
git log $* --name-status --color | awk "$(cat <<AWK
/^.*commit [0-9a-f]{40}/ {sha=substr(\$2,1,7)}
/^[MA]\t/ {printf "%s\thttps://github.com/$user_repo/blob/%s/%s\n", \$1, sha, \$2; next}
/.*/ {print \$0}
AWK
)" | less -F
}
# Just the last few commits, please!
for n in {1..5}; do alias gf$n="gf -n $n"; done
# OSX-specific Git shortcuts
if [[ "$OSTYPE" =~ ^darwin ]]; then
alias gdk='git ksdiff'
alias gdkc='gdk --cached'
alias gt='gittower -s'
fi