-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbashrc_git
More file actions
69 lines (58 loc) · 2.39 KB
/
bashrc_git
File metadata and controls
69 lines (58 loc) · 2.39 KB
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
# git-irebase-branch - interactive rebase current branch into another branch
girebasebranch() {
branches=$(git for-each-ref --count=30 --sort=-committerdate refs/heads/ --format="%(refname:short)") &&
branch=$(echo "$branches" |
fzf-tmux -d $(( 2 + $(wc -l <<< "$branches") )) +m) &&
git rebase -i $(echo "$branch" | sed "s/.* //" | sed "s#remotes/[^/]*/##")
}
# git-branch - checkout git branch sorted by most recent commit, limit 30 last branches
gbranch() {
local branches branch
branches=$(git-local-branches) &&
branch=$(echo "$branches" |
fzf-tmux -d $(( 2 + $(wc -l <<< "$branches") )) +m) &&
git checkout $(echo "$branch" | sed "s/.* //" | sed "s#remotes/[^/]*/##")
}
# git-delete-branch - delete local branch
gdeletebranch() {
local branches branch
branches=$(git-local-branches) &&
branch=$(echo "$branches" |
fzf-tmux -d $(( 2 + $(wc -l <<< "$branches") )) +m) &&
git branch -d $(echo "$branch" | sed "s/.* //")
}
# plumbing
alias git-ls-untracked='git ls-files --others --exclude-standard --relative'
alias git-ls-changed='git diff --name-only --relative'
alias git-ls-staged='git diff --name-only --staged --relative'
alias git-local-branches='git for-each-ref refs/heads/ --format="%(refname:short)"'
# git-add : support multiple file selection
alias gadd='git-ls-changed | fzf -m --print0 | xargs -0 -o -t git add'
gdiff() {
git diff $@ --name-only | fzf -m --ansi --preview-window=right:70% --preview "git diff $@ --color=always -- {-1}"
}
alias gdifff='git diff "$(git-ls-changed | fzf --prompt=git-diff-file:)"'
alias gdiffsf='git diff --staged "$(git-ls-staged | fzf --prompt=git-diff-staged-file:)"'
is_in_git_repo() {
git rev-parse HEAD > /dev/null 2>&1
}
fzf-down() {
fzf --height 80% "$@" --border
}
# git status
gstatus() {
is_in_git_repo || return
git -c color.status=always status --short |
fzf-down -m --ansi --nth 2..,.. \
--preview '(git diff --color=always -- {-1} | sed 1,4d; cat {-1}) | head -500' |
cut -c4- | sed 's/.* -> //'
}
# git log
glogs() {
is_in_git_repo || return
git log --date=short --format="%C(green)%C(bold)%cd %C(auto)%h%d %s (%an)" --graph --color=always |
fzf-down --ansi --no-sort --reverse --multi --bind 'ctrl-s:toggle-sort' \
--header 'Press CTRL-S to toggle sort' \
--preview 'grep -o "[a-f0-9]\{7,\}" <<< {} | xargs git show --color=always | head -'$LINES |
grep -o "[a-f0-9]\{7,\}"
}