-
Notifications
You must be signed in to change notification settings - Fork 38
/
git-recent-with-fzf-and-diff
executable file
·33 lines (24 loc) · 1.32 KB
/
git-recent-with-fzf-and-diff
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
#!/bin/bash
# git recent but with a FZF preview of the branch diff.
# run this somewhere:
# bind \cb git-recent-with-fzf-and-diff
# then do
# git checkout CTRL-B
branches_format="%(color:yellow)%(refname:short)%(color:reset)"
commits_format="%C(red bold)%h %C(bold blue)%an %C(bold green)%ad %Creset%s"
# This relies on my own git aliases. see .gitconfig
stat_cmd="git diff --color=always --stat origin/$(git mainormaster)...{}"
diffcommits_cmd="git log --date=human --color=always --format='$commits_format' --no-merges origin/$(git mainormaster)..{1}"
diffbranch_cmd="git diffbranch-that {} | delta"
# fzf basic inspiration:
# - https://github.com/junegunn/fzf/wiki/Examples#git, https://github.com/junegunn/fzf/wiki/Examples-(fish)#git
# Hardcore inspiration:
# - https://github.com/junegunn/fzf-git.sh
git for-each-ref --color=always --sort=-committerdate "refs/heads/" --format="$branches_format" \
| fzf-tmux --ansi -p80%,60% -- \
--layout=reverse --multi --height=90% --min-height=20 \
--border-label-pos=2 --border-label '🌲 Branches' --border \
--no-hscroll --no-multi \
--preview-window='right,70%,border-left,border-rounded' --preview="$diffcommits_cmd" --preview-label="Commits unique to branch" \
--header $'CTRL-O (branch diff)\n\n' \
--bind "ctrl-o:execute:$diffbranch_cmd"