mechanicker icon

Offline code review helper

mechanicker | PRO | 01/22/24 10:13:52 PM UTC (Edited) | 0 ⭐ | 1304 👁️ | Never ⏰ | []
Bash |

980 B

|

Source Code

|

0 👍

/

0 👎

#!/usr/bin/env zsh
# usage: greview <default_branch>
# example:
#       git checkout branch_to_review
#       greview master
 
base=${1:-master}
other=$(git rev-parse --abbrev-ref HEAD)
 
files=($(git diff --name-only ${base}..${other} | tr '\n' ' ' 2>/dev/null))
PROMPT3="select [x to exit]: "
 
while true; do
    select file in ${files[@]}; do
        case $file in
            *)
                if [[ "${REPLY}" =~ "^[0-9]+$" ]] ; then
                    file=${file/% \[x\]/}
                    if [ $REPLY -le $#files ] ; then
                        git difftool -t vimdiff ${base}..${other} ${file} 2>/dev/null
                        files[$REPLY]="${file} [x]"
                    fi
                    break
                elif [ "${REPLY}" = "x" ] ; then
                    echo "done..."
                    exit 0
                else
                    echo "invalid input: $REPLY, retry"
                fi
                ;;
        esac
    done
done
 

Comments