-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfzf-git.plugin.zsh
65 lines (55 loc) · 1.9 KB
/
fzf-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
if [[ $- == *i* ]]; then
__fzf_git_is_in_repo() {
git rev-parse HEAD > /dev/null 2>&1
}
__fzf_git_down() {
fzf --height 50% --border "$@"
}
__fzf_git_join_lines() {
local item
while read item; do
echo -n "${(q)item} "
done
}
__fzf_git_branch() {
__fzf_git_is_in_repo || return
git branch -a --color=always | grep -v '/HEAD\s' | sort \
| __fzf_git_down --ansi --multi --tac --preview-window right:70% \
--preview 'git log --oneline --graph --date=short --color=always --pretty="format:%C(auto)%cd %h%d %s" $(sed s/^..// <<< {} | cut -d" " -f1) | head -'$LINES \
| sed 's/^..//' | cut -d' ' -f1 \
| sed 's#^remotes/##'
}
__fzf_git_tag() {
__fzf_git_is_in_repo || return
git tag --sort -version:refname \
| __fzf_git_down --multi --preview-window right:70% \
--preview 'git show --color=always {} | head -'$LINES
}
__fzf_git_head() {
__fzf_git_is_in_repo || return
git log --date=short --format="%C(green)%C(bold)%cd %C(auto)%h%d %s (%an)" --graph --color=always \
| __fzf_git_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,\}"
}
__fzf_git_remote() {
__fzf_git_is_in_repo || return
git remote -v | awk '{print $1 "\t" $2}' | uniq \
| __fzf_git_down --tac \
--preview 'git log --oneline --graph --date=short --pretty="format:%C(auto)%cd %h%d %s" {1} | head -200' \
| cut -d$'\t' -f1
}
__fzf_git_bind_helper() {
eval "fzf-git-$1-widget() { \
LBUFFER=\"\${LBUFFER}\$(__fzf_git_$1 | __fzf_git_join_lines)\"; \
zle reset-prompt; \
}"
eval "zle -N fzf-git-$1-widget"
eval "bindkey '$2' fzf-git-$1-widget"
}
__fzf_git_bind_helper "branch" "^G^B"
__fzf_git_bind_helper "tag" "^G^T"
__fzf_git_bind_helper "head" "^G^H"
__fzf_git_bind_helper "remote" "^G^R"
fi