1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Emacsでファイル保存しながらiTerm2でコマンドを実行する

Last updated at Posted at 2020-04-29

Terraformを勉強してる時に都度Emacsでコード書いて、iTermで実行というのが面倒だった。
そしてEmacsからコマンドを実行する方法を試したがコマンド実行中に他プロセスを実行するというのが上手にできなかったり絵文字が表示できなかったり不便だったのでAppleScriptとして別に別けた。
ネットワークアクセスが発生し時間がかかるコマンドと組み合わせると効果が高い。
今回は例としてterraform applyを実行しているが、一回書けば応用が効くと思うのでオススメ。(多分引数として渡せばもっと便利かなあ)

まずはAppleScriptの準備。

下記のscptファイルを任意の場所に保存する。

iterm.scpt
tell application "iTerm"
	set _current_session to current session of current window
	tell _current_session
		# ここに操作したいことを書く
		write text "terraform apply"
	end tell
end tell

init.elで関数定義

emacs-lispは単純で、あとは関数定義とキーマップに割り当てるだけ。

init.el
(defun tf-apply ()
  "Save and terraform apply"
       (interactive)
       (save-buffer)
       (shell-command "osascript ~/.emacs.d/script/iterm.scpt"
(global-set-key (kbd "C-c u a") 'tf-apply)

(参考)
iTermをAppleScriptで操作する

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?