File tree Expand file tree Collapse file tree 2 files changed +54
-45
lines changed Expand file tree Collapse file tree 2 files changed +54
-45
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ function code-review () {
2
+ local is_git=$( git rev-parse --is-inside-work-tree 2> /dev/null)
3
+ if [ -z $is_git ]; then
4
+ echo " not a git repository"
5
+ return
6
+ fi
7
+
8
+ local base_branch=${1:- ${GIT_BASE_BRANCH:- master} }
9
+ local target_branch=${2:- HEAD}
10
+
11
+ local merge_base=$( git merge-base $target_branch $base_branch )
12
+
13
+ local shortstatout=$( git diff --shortstat --color $merge_base $target_branch )
14
+ local statout=$( git diff --stat --color $merge_base $target_branch )
15
+ local filesout=$( git diff --name-only $merge_base $target_branch )
16
+
17
+ local LESS
18
+ local selectfile
19
+
20
+ setopt localtraps
21
+ trap ' ' 2
22
+
23
+ while true ; do
24
+ # alternate screen
25
+ echo -ne " \e[?1049h"
26
+ # clear screen; move to top left
27
+ echo -ne " \e[2J\e[H"
28
+ echo " comparing $base_branch ..$target_branch "
29
+ echo $shortstatout
30
+ echo -n " Usage: l - list changed files, f - launch difftool for file, q - quit"
31
+ read -sk opt
32
+ case $opt in
33
+ (l)
34
+ echo $statout | less -c -g -i -M -R -S -w -X -z-4
35
+ ;;
36
+ (f)
37
+ selectfile=$( echo " $filesout " | fzf --reverse --preview ' [[ $(file --mime {}) =~ binary ]] && echo {} is a binary file || (bat --color=always -r :$FZF_PREVIEW_LINES {} || head -$FZF_PREVIEW_LINES {}) 2> /dev/null' )
38
+ # alternate screen
39
+ echo -ne " \e[?1049h"
40
+ echo selectfile: " begin${selectfile} end"
41
+ if [ -z $selectfile ]; then
42
+ else
43
+ git difftool --no-prompt $merge_base $target_branch -- $selectfile
44
+ fi
45
+ ;;
46
+ (q)
47
+ break
48
+ ;;
49
+ esac
50
+ done
51
+
52
+ # revert alternate screen
53
+ echo -ne " \e[?1049l"
54
+ }
You can’t perform that action at this time.
0 commit comments