Created
January 6, 2022 19:09
-
-
Save ecatmur/6618cb00fe7f886430d9f578f9b5a1ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
NOBLOB=0000000000000000000000000000000000000000 | |
root=$(git rev-parse --show-toplevel) || exit | |
revs=() | |
for arg; do | |
if [[ $arg == *...* ]] ; then | |
revs+=($(git name-rev --name-only --always ${arg%...*}) | |
$(git name-rev --name-only --always ${arg#*...})) | |
elif [[ $arg == *..* ]] ; then | |
revs+=($(git name-rev --name-only --always ${arg%..*}) | |
$(git name-rev --name-only --always ${arg#*..})) | |
elif git rev-parse --verify $arg >/dev/null 2>&1; then | |
revs+=($(git name-rev --name-only --always $arg)) | |
fi | |
done | |
: ${EDITOR:=gvim} | |
[[ "${EDITOR}" == vim && "${DISPLAY}" ]] && EDITOR=gvim | |
"$EDITOR" -s <( | |
echo ":let &columns+=&columns + 5" | |
git --no-pager diff --raw --abbrev=40 --find-renames=1% "$@" \ | |
| cut -c2- \ | |
| while read oldmode newmode oldblob newblob status oldname newname; do | |
: ${newname:=$oldname} | |
echo ":cd $root" | |
echo ":tabnew" | |
echo ":setlocal noswapfile" | |
if [[ $newblob == $NOBLOB ]]; then | |
echo ":e $oldname" | |
else | |
if diff -q <(git --no-pager show $newblob) "$newname" >/dev/null 2>/dev/null; then | |
echo ":e $newname" | |
else | |
echo ":0read ++edit !git --no-pager show $newblob" | |
echo ":normal Gdd" | |
fi | |
if [[ "${revs[1]}" && "$newname" ]]; then | |
echo ":set buftype=nofile" | |
echo ":file ${revs[1]}:$newname" | |
elif [[ "${revs[1]}" ]]; then | |
echo ":set buftype=nofile" | |
echo ":file ${revs[1]}:$oldname" | |
elif [[ "$newname" ]]; then | |
echo ":file $newname" | |
else | |
echo ":file $oldname" | |
fi | |
echo ":filetype detect" | |
fi | |
echo ":vert diffsplit" | |
echo ":enew" | |
echo ":setlocal noswapfile" | |
echo ":set buftype=nofile" | |
if [[ $oldblob != $NOBLOB ]]; then | |
echo ":0read ++edit !git --no-pager show $oldblob" | |
echo ":normal Gdd" | |
fi | |
if [[ "${revs[0]}" ]]; then | |
echo ":file ${revs[0]}:$oldname" | |
else | |
echo ":file $oldname" | |
fi | |
echo ":filetype detect" | |
echo ":diffthis" | |
echo ":diffup" | |
echo ":wincmd l" | |
echo ":0" | |
done | |
[[ ${PIPESTATUS[0]} == 0 ]] || echo ":q" | |
echo ":tabfirst" | |
echo ":tabclose" | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment