Skip to content

Instantly share code, notes, and snippets.

@wesalvaro
Last active June 25, 2018 09:08
Show Gist options
  • Save wesalvaro/571154aa9391e895a6b3cfe28ed55c3c to your computer and use it in GitHub Desktop.
Save wesalvaro/571154aa9391e895a6b3cfe28ed55c3c to your computer and use it in GitHub Desktop.
Simple Word Diff (wdiff) Wrapper for Mercurial
function dowdiff() {
wdiff \
-w $'\e[91m' \
-x $'\e[0m' \
-y $'\e[92m' \
-z $'\e[0m' \
$1 $2
}
function findwdiff() {
local diff=$(mktemp /tmp/wdiff-full.XXXXX)
local left=$(mktemp /tmp/wdiff-left.XXXXX)
local right=$(mktemp /tmp/wdiff-right.XXXXX)
diff \
--recursive \
--unified=5 \
"${1}" "${2}" > $diff
local indiff=false
IFS=''
while read i; do
if [[ $i = @@* ]]; then
# @@ -49,6 +49,10 @@
echo -en "\e[93m${i}" | sed -E "s/@@ -(\w+),.*$/:\1/"
echo -e "\x1B[K\e[0m"
elif [[ $i = +++* ]]; then
echo -e "\e[34m${i#+++ }\x1B[K\e[0m"
elif [[ $i = ---* ]]; then
:
elif [[ $i = diff* ]]; then
:
elif [[ $i = +* ]]; then
echo "${i#+}" >> $right
indiff=true
elif [[ $i = -* ]]; then
echo "${i#-}" >> $left
indiff=true
else
if [ "$indiff" = true ]; then
dowdiff $left $right
: > $left
: > $right
indiff=false
fi
echo "${i## }"
fi
done <$diff
if [ "$indiff" = true ]; then
dowdiff $left $right
fi
rm $diff $left $right
}
findwdiff $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment