-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-stack
More file actions
executable file
·87 lines (73 loc) · 1.97 KB
/
git-stack
File metadata and controls
executable file
·87 lines (73 loc) · 1.97 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env bash
#!/usr/bin/env zsh
#
# Show the difference between the selected branch and master branch
# Color scheme used exclusively in git-fuzzy-commit
export FZF_DEFAULT_OPTS='
--color hl:33,fg+:214,hl+:33
--color spinner:208,pointer:196,marker:208
'
function main() {
# Check if it's a git repo
[[ $(git root 2>&1) == 'Not a git repo!' ]] && echo "Not a git repo!" && exit 1
# Assign master to $branch if not defined yet
local branch
[[ -z "$1" ]] && branch='master' || branch=$1
function git-stack() {
glNoGraph() {
git log "$branch".. --color=always --format="%C(auto)%h%d %s %C(black)%C(bold)%cr% C(auto)%an" "$@"
}
_gitLogLineToHash="echo {} | grep -o '[a-f0-9]\{7\}' | head -1"
_viewGitLogLine="$_gitLogLineToHash | xargs -I % sh -c 'git show --color=always % | diff-so-fancy'"
glNoGraph |
fzf --cycle --no-sort --reverse --tiebreak=index --no-multi \
--ansi --preview="$_viewGitLogLine" \
--header "enter to view, alt-y to copy hash" \
--bind "enter:execute:$_viewGitLogLine | less -R" \
--bind "alt-y:execute:$_gitLogLineToHash | xclip"
}
git-stack
}
function fuzzy_select_branch() {
# Check if it's a git repo
[[ $(git root 2>&1) == 'Not a git repo!' ]] && echo "Not a git repo!" && exit 1
result=$(git branch --list |
fzf --reverse --height=40% --cycle
)
branch=$(echo "$result" |
tr "*" " " |
xargs # Remove trailing whitespaces
)
[[ -n "$branch" ]] && main $branch
}
################ Help ################
usage="usage: $(basename "$0") [<options>]
Compare against master branch with fzf
where:
-h show this help text
-f fuzzy select a branch to compare with"
############# Parse options ##############
while getopts ':hf' option; do
case "$option" in
h)
echo "$usage"
exit 0
;;
f)
fuzzy_select_branch
exit
;;
:)
main
exit
;;
\?)
printf "illegal option: -%s\n" "$OPTARG" >&2
echo -e "$usage" >&2
exit 1
;;
esac
done
shift $((OPTIND - 1))
# Default case when no option provided
main