Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
another (unsuccessful) stab at making ediff.sh work
- Loading branch information
Showing
1 changed file
with
44 additions
and
7 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |