Skip to content

Instantly share code, notes, and snippets.

@mcav
Created October 10, 2013 18:05
Show Gist options
  • Save mcav/6922811 to your computer and use it in GitHub Desktop.
Save mcav/6922811 to your computer and use it in GitHub Desktop.
Executes the most recent iTerm command from right within Emacs. Useful for unit testing, etc.
(defun exec-last-iterm-command ()
(interactive)
(do-applescript
(concat
"set currentApp to (path to frontmost application as text)\r"
"tell application \"iTerm\" to activate\r"
"tell application \"System Events\"\r"
" delay 0.1\r"
" keystroke \"p\" using control down\r"
" keystroke return\r"
"end tell\r"
"tell application currentApp to activate\r")))
(global-set-key (kbd "M-RET") 'exec-last-iterm-command)
@mcav
Copy link
Author

mcav commented Oct 10, 2013

The reason I didn't just tell iTerm (which supports applescript) to write "!!" is because zsh doesn't actually execute the command when you type that. I didn't want to rely on specific terminal options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment