chiark / gitweb /
el/dot-emacs.el (mdw-fontify-rust): Fix integer literal syntax.
[profile] / bin / emerge-hack
CommitLineData
547fb8af
MW
1#! /bin/sh
2set -e
3
4### Huh?
5###
6### This script is an adaptor for git mergetool so that, while /it/ thinks
7### it's using emerge, it's really using ediff, which is much better, and
8### maybe a long-running Emacs via gnuserv.
9
10## Find out what we're supposed to be doing. The command line looks like
11##
12## emerge-hack -f emerge-mumble FILE FILE ... OUTPUT
13
14dashf=$1
15command=$2
16shift 2
17case "$dashf" in
18 -f) ;;
19 *) echo >&2 "$0: expected -f emerge-mumble"; exit 1;;
20esac
21
22case "$command" in
23 emerge-files-with-ancestor-command)
24 func=ediff-merge-files-with-ancestor
25 ;;
26 emerge-merge-files-command)
27 func=ediff-files
28 ;;
29 *)
30 echo >&2 "$0: unexpected command $command"
31 exit 1
32 ;;
33esac
34
35## Find out whether there's a plausible-looking gnuserv.
36
37if gnuclient -batch -eval t >/dev/null 2>&1; then
38 emacs="gnuclient"
39else
40 emacs="emacs"
41fi
42
43## Now build the command line.
44##
45## The hairy-looking seddery is there to quotify file names properly for
46## Lisp. We also need to make sure that the filenames are absolute.
47## Finally, there's a little tweak to separate off the last name because of
48## the strange argument order ediff uses.
49
50expr=""
51sep=""
52last="$func"
53
54for i; do
55 name=$i
56 case "$name" in
57 /*);;
58 *) name=`pwd`/$name;;
59 esac
60 quot=$(echo -n "$name" |
61 sed -n '
62 1 h
63 2,$ H
64 $ {
65 g
66 s/["\\]/\\&/
67 s/^/"/
68 s/$/"/
69 s/\
70/\\n/
71 p
72 }
73')
74 expr="$expr$sep$last"
75 sep=" "
76 last=$quot
77 output=$name
78done
79
80## Done. Note that we pass the output filename again, as an explicit
81## argument. This will make gnuclient wait until we've finished with the
82## merge.
83
84exec "$emacs" -eval "($expr${sep}nil $last)" "$output"