-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit_ch.sh
More file actions
executable file
·59 lines (58 loc) · 2.1 KB
/
git_ch.sh
File metadata and controls
executable file
·59 lines (58 loc) · 2.1 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
#!/bin/bash
git_show() {
branch_commits='git log --graph --color --format="%C(white)%h - %C(green)%cs - %C(blue)%s%C(red)%d"' \
&& all_commits='git log --all --graph --color --format="%C(white)%h - %C(green)%cs - %C(blue)%s%C(red)%d"' \
&& eval "$branch_commits" | fzf \
--ansi \
--reverse \
--no-sort \
--prompt="Branch > " \
--preview='
hash=$(echo {} | grep -o "[a-f0-9]\{7\}" | sed -n "1p") \
&& [[ $hash != "" ]] \
&& git show --color $hash
' \
--bind="ctrl-s:transform:[[ \$FZF_PROMPT =~ 'Branch >' ]] \
&& echo 'change-prompt(All > )+reload($all_commits)' \
|| echo 'change-prompt(Branch > )+reload($branch_commits)'" \
--bind='enter:execute(
hash=$(echo {} | grep -o "[a-f0-9]\{7\}" | sed -n "1p") \
&& [[ $hash != "" ]] \
&& sh -c "git show --color $hash | less -R"
)' \
--bind='ctrl-c:execute(
hash=$(echo {} | grep -o "[a-f0-9]\{7\}" | sed -n "1p") \
&& [[ $hash != "" ]] \
&& git checkout $hash
)+abort' \
--bind='ctrl-r:execute(
hash=$(echo {} | grep -o "[a-f0-9]\{7\}" | sed -n "1p") \
&& [[ $hash != "" ]] \
&& git reset $hash
)+abort' \
--bind='ctrl-i:execute(
hash=$(echo {} | grep -o "[a-f0-9]\{7\}" | sed -n "1p") \
&& [[ $hash != "" ]] \
&& git rebase --interactive $hash
)+abort' \
--bind='ctrl-p:execute(
hash=$(echo {} | grep -o "[a-f0-9]\{7\}" | sed -n "1p") \
&& [[ $hash != "" ]] \
&& git cherry-pick $hash
)+abort' \
--bind='ctrl-f:execute(
hash=$(echo {} | grep -o "[a-f0-9]\{7\}" | sed -n "1p") \
&& [[ $hash != "" ]] \
&& git commit -a --fixup=$hash --no-verify \
&& git rebase --autosquash --interactive $hash~1
)+abort' \
--header-first \
--header '
> ENTER to display the diff
> ctrl-C to checkout the commit | ALT-R to reset to the commit
> ctrl-I to rebase interactively
> ctrl-P to cherry pick
> ctrl-F to fixup
'
}
git_show