dot/screenrc: Add a binding for the `kill' command.
[profile] / bin / emerge-hack
1 #! /bin/sh
2 set -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
14 dashf=$1
15 command=$2
16 shift 2
17 case "$dashf" in
18 -f) ;;
19 *) echo >&2 "$0: expected -f emerge-mumble"; exit 1;;
20 esac
21
22 case "$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 ;;
33 esac
34
35 ## Find out whether there's a plausible-looking gnuserv.
36
37 if gnuclient -batch -eval t >/dev/null 2>&1; then
38 emacs="gnuclient"
39 else
40 emacs="emacs"
41 fi
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
50 expr=""
51 sep=""
52 last="$func"
53
54 for 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
78 done
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
84 exec "$emacs" -eval "($expr${sep}nil $last)" "$output"