-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit.plugin.zsh
86 lines (78 loc) · 2.76 KB
/
git.plugin.zsh
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# gcheckout - checkout local|remote branch
function gcheckout() {
if [[ -n $1 ]] then
git checkout -b "$@"
else
local branches branch
branches=$(git branch --all | grep -v HEAD) &&
branch=$(echo "$branches" | fzf-tmux -d $(( 2 + $(wc -l <<< "$branches") )) +m) &&
git checkout $(echo "$branch" | sed "s/.* //" | sed "s#remotes/[^/]*/##")
fi
}
# gshow - commit browser
function gshow() {
git log --graph --color=always \
--format="%C(auto)%h%d %s %C(black)%C(bold)%cr" "$@" |
fzf --select-1 --ansi --no-sort --reverse --tiebreak=index --bind=ctrl-s:toggle-sort \
--bind "ctrl-m:execute:
(grep -o '[a-f0-9]\{7\}' | head -1 |
xargs -I % sh -c 'git show --color=always % | less -R') << 'FZF-EOF'
{}
FZF-EOF"
}
# gfix - git commit -a --fixup
function gfix() {
local commits commitId
commits=$(git log --oneline --decorate)
while read -r commit; do
if [[ $commit != *fixup\!* ]]; then
commitId=$(echo $commit | awk '{print $1;}')
git commit -a --fixup $commitId
break
fi
done <<< "$commits"
}
# grauto - git rebase -i --autosquash
function grauto() {
local commits
commits=$(git log --oneline --decorate)
local counter=0
while read -r commit; do
if [[ $commit == *fixup\!* ]]; then
counter=$((counter+1))
else
GIT_SEQUENCE_EDITOR=: git rebase -i --autosquash HEAD~$((counter+1))
break
fi
done <<< "$commits"
}
# gcshow - get git commit SHA-1
function gcshow() {
local commits commit
commits=$(git log --color=always --pretty=oneline --abbrev-commit --reverse) &&
commit=$(echo "$commits" | fzf --tac +s +m -e --ansi --reverse) &&
echo -n $(echo "$commit" | sed "s/ .*//")
}
# gcheckout - checkout local|remote branch
function grebase() {
local branches branch
branches=$(git branch -r | grep -v HEAD) &&
branch=$(echo "$branches" | fzf-tmux -d $(( 2 + $(wc -l <<< "$branches") )) +m) &&
git fetch $(echo "$branch" | sed "s/.* //" | cut -d "/" -f 1) $(echo "$branch" | sed "s/.* //" | cut -d "/" -f 2-15) &&
git rebase FETCH_HEAD
}
# grebase - interactive rebase
alias grebasei='git rebase -i `gcshow`'
# gdelete - branch -d of merged branches
function gdelete() {
local branches branch
branches=$(git branch --merge) &&
branch=$(echo "$branches" | fzf-tmux -d 15 +s +m) &&
git branch -d $(echo "$branch" | sed "s/.* //")
}
# gpremotes - creates local branches of all remote branches
function gpremotes(){
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v $(git rev-parse --abbrev-ref HEAD) `; do
git branch --track ${branch#remotes/origin/} $branch
done
}