forked from asbjornu/dotfiles-old
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.functions
47 lines (42 loc) · 1.34 KB
/
.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# define md
md () { mkdir -p "$@" && cd "$@"; }
# 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
# Change the extension of files from $1 to $2
function cext() {
if (( "${#@}" != 2 )); then
echo "Changes the extension from <X> to <Y>."
echo " Usage: cext X Y"
return 1;
fi
find -L . -type f -name "*.$1" -print0 | while IFS= read -r -d '' FNAME; do
mv -v -- "$FNAME" "${FNAME%.$1}.$2"
done
}