File tree Expand file tree Collapse file tree 1 file changed +24
-10
lines changed Expand file tree Collapse file tree 1 file changed +24
-10
lines changed Original file line number Diff line number Diff line change 1
1
#! /usr/bin/env zsh
2
2
3
+ set -e
4
+
3
5
base_branch=${1:- ${GIT_BASE_BRANCH:- master} }
4
6
target_branch=${2:- HEAD}
5
7
6
8
merge_base=$( git merge-base $target_branch $base_branch )
7
9
8
- echo comparing $base_branch ..$target_branch
9
- git diff --shortstat $merge_base $target_branch
10
+ shortstatout=$( git diff --shortstat --color $merge_base $target_branch )
11
+ statout=$( git diff --stat --color $merge_base $target_branch )
12
+ filesout=$( git diff --name-only $merge_base $target_branch )
13
+
14
+ unset LESS
10
15
11
- files=$( git diff --name-only $merge_base $target_branch )
16
+ function cleanup () {
17
+ echo -ne " \e[?1049l"
18
+ exit
19
+ }
20
+ trap " cleanup" 2
12
21
13
22
while true ; do
23
+ # alternate screen
24
+ echo -ne " \e[?1049h"
25
+ # clear screen; move to top left
26
+ echo -ne " \e[2J\e[H"
27
+ echo " comparing $base_branch ..$target_branch "
28
+ echo $shortstatout
29
+ echo " Usage: l - list changed files, f - launch difftool for file, q - quit"
14
30
read -sk opt
15
31
case $opt in
16
32
l)
17
- git diff --stat $merge_base $target_branch
33
+ echo $statout | less -c -g -i -M -R -S -w -X -z-4
18
34
;;
19
35
f)
20
- file=$( echo " $files " | fzf)
21
- git difftool --no-prompt $merge_base $target_branch -- $file
36
+ file=$( echo " $filesout " | fzf) && git difftool --no-prompt -x ' nvim -R -d' $merge_base $target_branch -- $file
22
37
;;
23
38
q)
24
39
break
25
40
;;
26
- * )
27
- echo -ne " \r\e[0K"
28
- echo -n " Usage: l - list changed files, f - launch difftool for file, q - quit"
29
- ;;
30
41
esac
31
42
done
43
+
44
+ # revert alternate screen
45
+ cleanup
You can’t perform that action at this time.
0 commit comments