Last active
January 5, 2025 04:17
-
-
Save PhilipRoman/60066716b5fa09fcabfa6c95eaf7d170 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/sh | |
# Put in gitconfig: | |
# [alias] | |
# bvd = difftool -d -x bettervimdiff | |
dirA="$1" | |
dirB="$2" | |
if ! [ -d "$dirA" -a -d "$dirB" ]; then | |
echo 'Usage: bettervimdiff DIR1 DIR2' >&2 | |
exit 1 | |
fi | |
tmpfile="$(mktemp)" | |
find "$dirA" "$dirB" -type f -printf '%P\n' | | |
awk '!a[$0] {print $0; a[$0]=1}' | | |
awk -vA="$dirA" -vB="$dirB" ' | |
BEGIN { | |
first=1 | |
escapeA=A | |
escapeB=B | |
gsub(/([^[:alnum:]\/])/, "\\\\&", escapeA) | |
gsub(/([^[:alnum:]\/])/, "\\\\&", escapeB) | |
} | |
{ | |
escapeFile=$0 | |
gsub(/([^[:alnum:]\/])/, "\\\\&", escapeFile) | |
} | |
!first { | |
print ":tabnew" | |
} | |
{ | |
fileA=A"/"$0 | |
fileB=B"/"$0 | |
if((getline _ < fileB) != -1) | |
print ":view "escapeB"/"escapeFile | |
else | |
print ":view /dev/null" | |
print ":vsplit" | |
if((getline _ < fileA) != -1) | |
print ":view "escapeA"/"escapeFile | |
else | |
print ":view /dev/null" | |
print ":windo diffthis" | |
} | |
first { | |
first=0 | |
} | |
' >"$tmpfile" | |
exec 3<"$tmpfile" | |
/usr/bin/vim --noplugins +'set nosplitright' +'silent source /dev/fd/3' +'set splitright' | |
#cat "$tmpfile" | |
rm "$tmpfile" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment