Skip to content

Commit

Permalink
another (unsuccessful) stab at making ediff.sh work
Browse files Browse the repository at this point in the history
  • Loading branch information
nhoffman committed Apr 21, 2016
1 parent cb17f23 commit 4aa5cf0
Showing 1 changed file with 44 additions and 7 deletions.
51 changes: 44 additions & 7 deletions bin/ediff.sh
@@ -1,18 +1,55 @@
#!/bin/bash

if [[ -z $2 ]]; then
echo "USAGE: ediff <FILE 1> <FILE 2>"
# modified from http://ulf.zeitform.de/en/documents/git-ediff.html

# test args
if [ ! ${#} -ge 3 ]; then
echo 1>&2 "Usage: ${0} LOCAL REMOTE MERGED BASE"
echo 1>&2 " (LOCAL, REMOTE, MERGED, BASE can be provided by \`git mergetool'.)"
exit 1
fi

# tools
if [[ $(uname) == 'Darwin' ]]; then
EMACS=/Applications/Emacs.app/Contents/MacOS/Emacs
_EGREP=/usr/bin/egrep
_MKTEMP=/usr/bin/mktemp
else
_EMACS=emacs
_EGREP=/bin/egrep
_MKTEMP=/bin/mktemp
fi

_BASENAME=/usr/bin/basename
_CP=/bin/cp

# args
_LOCAL=${1}
_REMOTE=${2}
_MERGED=${3}
if [ ${4} -a -r ${4} ] ; then
_BASE=${4}
_EDIFF=ediff-merge-files-with-ancestor
_EVAL="${_EDIFF} \"${_LOCAL}\" \"${_REMOTE}\" \"${_BASE}\" nil \"${_MERGED}\""
elif [ ${_REMOTE} = ${_MERGED} ] ; then
_EDIFF=ediff
_EVAL="${_EDIFF} \"${_LOCAL}\" \"${_REMOTE}\""
else
EMACS=emacs
_EDIFF=ediff-merge-files
_EVAL="${_EDIFF} \"${_LOCAL}\" \"${_REMOTE}\" nil \"${_MERGED}\""
fi

TERM=xterm-256color ${EMACS:?} -nw -q \
--eval "(setq ediff-split-window-function 'split-window-horizontally)" \
--eval "(ediff-files \"$1\" \"$2\")"
# run emacsclient
${_EMACS} -nw -q --eval "(${_EVAL})" 2>&1

# check modified file
if [ ! $(egrep -c '^(<<<<<<<|=======|>>>>>>>|####### Ancestor)' ${_MERGED}) = 0 ]; then
_MERGEDSAVE=$(${_MKTEMP} --tmpdir `${_BASENAME} ${_MERGED}`.XXXXXXXXXX)
${_CP} ${_MERGED} ${_MERGEDSAVE}
echo 1>&2 "Oops! Conflict markers detected in $_MERGED."
echo 1>&2 "Saved your changes to ${_MERGEDSAVE}"
echo 1>&2 "Exiting with code 1."
exit 1
fi

rm -f $script
exit 0

0 comments on commit 4aa5cf0

Please sign in to comment.