Skip to content

Instantly share code, notes, and snippets.

@nobrowser
Created February 1, 2016 22:09
Show Gist options
  • Save nobrowser/667c21d243aa040d2a74 to your computer and use it in GitHub Desktop.
Save nobrowser/667c21d243aa040d2a74 to your computer and use it in GitHub Desktop.
Interactive 3 way merge a la git, for use as unison merge tool
#! /bin/sh -Cefu
PATH=/bin:/usr/bin:/usr/local/bin
EDITOR=${VISUAL:-emacs}
# interactive merge a la git
# first, dump marked differences into a temporary file.
# ignore the exit status which just means conflicts have been found
t=$( mktemp idiff3.XXXXXXXXXXXX )
diff3 --label=local --label=old --label=remote -m $1 $2 $3 >> $t || true
# next, interactively edit the marked file
"${EDITOR}" $t
# hacky but simple: nonempty temp file means signed off
size=$( stat --printf='%s' $t )
case $size in
(0)
rm -f $t
exit 3
;;
(*)
mv -i $t $4
exit 0
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment