I’ve been using tmux for a while now, and I recently started a new position where I’m using Elixir.
I’ve been using it to run IEx, the Elixir REPL. I’ve been annoyed by the fact that IEx doesn’t react to ^D (quit) and ^L (clear screen) like other REPLs do, so I decided look for a solution.
Quitting IEX being almost like quitting Vi, and since the team doesn’t seem to have any intention to change this, I decided to use tmux bindings to make it happen.
I was inspired by this post which uses AutoKey but it only supports X11 and I didn’t like the idea of interfacing too far away from the terminal.
As it’s not possible to add key bindings directly at the shell level, the next best thing is to use tmux bindings.
I added the following lines to my .tmux.conf
:
bind -n C-d if -F "#{m:*iex*,#{pane_title}}" 'send-keys C-\\' "send-keys C-d"
bind -n C-l if -F "#{m:*iex*,#{pane_title}}" 'send-keys clear\n' "send-keys C-l"
All it does is checking that the current pane runs iex, and if so, it sends the appropriate key sequence.
C-\
is the sequence for quitting iexclear\n
is the sequence for clearing the screen
If the pane doesn’t run iex, it just sends the unmodified key sequence.
I’m pretty happy with the result, and I hope it can help someone else.