I'm putting together a presentation that involves some live demos in the terminal. In one of the demos, I run a shell script that takes an input file, runs it through an Awk script, and generates a transformed output file. After doing so, I'd like to display the diff between the input and output files.
Ediff is perfect for this, since it colors the diff and I can navigate easily with
p. However, I've only been using a gui Emacs. If I start ediff in terminal emacs, the coloring seems to be absent, and other things are just wonky, since I've been gui-centric in my configuration.
I'd like to have the shell script focus a running gui Emacs and run ediff on the two files. I'm on macOS, and I have a shell script that uses applescript to focus Emacs, but I don't know of a way it could tell Emacs to evaluate an expression.
My current workaround is to add a keybinding in my init.el that will launch the desired ediff session, and have my script simply launch/focus Emacs. Then it's up to me to hit the keybinding.
The demo shell script looks like:
#!/usr/bin/env bash input=/path/to/input output=/path/to/output awk_script=/path/to/awk_script awk -f "$awk_script" "$input" > "$output" e
e script launches/focuses emacs. It can be seen here, but the gist of it is:
osascript -e "tell application \"$emacs_app\" to activate"
And in my init.el, I've added:
(defun ivan-demo-ediff () (interactive) (ediff-files "/path/to/input" "/path/to/output")) (global-set-key [f2] #'ivan-demo-ediff)
Is there a better way to do this?