Advertisement
mechanicker

Offline code review helper

Jan 22nd, 2024 (edited)
1,014
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.98 KB | Source Code | 0 0
  1. #!/usr/bin/env zsh
  2. # usage: greview <default_branch>
  3. # example:
  4. #       git checkout branch_to_review
  5. #       greview master
  6.  
  7. base=${1:-master}
  8. other=$(git rev-parse --abbrev-ref HEAD)
  9.  
  10. files=($(git diff --name-only ${base}..${other} | tr '\n' ' ' 2>/dev/null))
  11. PROMPT3="select [x to exit]: "
  12.  
  13. while true; do
  14.     select file in ${files[@]}; do
  15.         case $file in
  16.             *)
  17.                 if [[ "${REPLY}" =~ "^[0-9]+$" ]] ; then
  18.                     file=${file/% \[x\]/}
  19.                     if [ $REPLY -le $#files ] ; then
  20.                         git difftool -t vimdiff ${base}..${other} ${file} 2>/dev/null
  21.                         files[$REPLY]="${file} [x]"
  22.                     fi
  23.                     break
  24.                 elif [ "${REPLY}" = "x" ] ; then
  25.                     echo "done..."
  26.                     exit 0
  27.                 else
  28.                     echo "invalid input: $REPLY, retry"
  29.                 fi
  30.                 ;;
  31.         esac
  32.     done
  33. done
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement