Skip to content

Commit 947f680

Browse files
committed
Update code-review script
1 parent f107d7a commit 947f680

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

code-review

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,45 @@
11
#!/usr/bin/env zsh
22

3+
set -e
4+
35
base_branch=${1:-${GIT_BASE_BRANCH:-master}}
46
target_branch=${2:-HEAD}
57

68
merge_base=$(git merge-base $target_branch $base_branch)
79

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
1015

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
1221

1322
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"
1430
read -sk opt
1531
case $opt in
1632
l)
17-
git diff --stat $merge_base $target_branch
33+
echo $statout | less -c -g -i -M -R -S -w -X -z-4
1834
;;
1935
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
2237
;;
2338
q)
2439
break
2540
;;
26-
*)
27-
echo -ne "\r\e[0K"
28-
echo -n "Usage: l - list changed files, f - launch difftool for file, q - quit"
29-
;;
3041
esac
3142
done
43+
44+
# revert alternate screen
45+
cleanup

0 commit comments

Comments
 (0)