MacOS (JIS キーボード) で terminal の代わりに alacritty を使う + tmux の設定

alacritty は、一言で言うと速いターミナル。

インストールは以下の2つあたりを参考に。Homebrew よりも上の GitHub からの方が安定しそう。

Alacritty integration with Tmux · Fatih Arslan

alacrittyインストール 備忘録 - replicityの日記

$ curl https://sh.rustup.rs -sSf | sh
$ echo export PATH="$HOME/.cargo/bin:$PATH" >> $HOME/.bash_profile; source $HOME/.bash_profile
$ git clone https://github.com/jwilm/alacritty; cd alacritty
$ rustup override set stable
$ rustup update stable
$ cargo build --release
$ make app

これで alacritty/target/release/osx/Alacritty.app が生成される。

configuration は上の一番目の記事を参考に。

Emacs のためにメタキーが欲しいが、そのままだと(JISキーボードの場合は?)うまくいかないので、作った ~/.config/alacritty/alacritty.yml 中のキーバインドhttps://github.com/jwilm/alacritty/issues/62 にあるキーバインド一覧を追加。

ついでに tmux の設定。これも基本的に上の一番目の記事で事足りるが、方向キー(arrow key)の扱いだけうまくいかなかったのでそこは https://gist.github.com/aergonaut/b26098988caf82106f771b535105b5d8 を採用。個人的な好みでプレフィックスキーに command キーを使用している(terminal っぽくないですか?)。

# alacritty.yml
  - { key: D,     mods: Command,       chars: "\x02\x64" }   # detach a session
  - { key: T,     mods: Command,       chars: "\x02\x63" }   # create a window
  - { key: P,     mods: Command,       chars: "\x02\x25" }   # create a horizontal pane
  - { key: P,     mods: Command|Shift, chars: "\x02\x22" }   # create a vertical pane
  - { key: W,     mods: Command,       chars: "\x02\x78" }   # close a pane (close a window with a single pane)
  - { key: Key1,  mods: Command,       chars: "\x02\x31" }   # jump to the window 1
  - { key: Key2,  mods: Command,       chars: "\x02\x32" }
  - { key: Key3,  mods: Command,       chars: "\x02\x33" }
  - { key: Key4,  mods: Command,       chars: "\x02\x34" }
  - { key: Key5,  mods: Command,       chars: "\x02\x35" }
  - { key: Key6,  mods: Command,       chars: "\x02\x36" }
  - { key: Key7,  mods: Command,       chars: "\x02\x37" }
  - { key: Key8,  mods: Command,       chars: "\x02\x38" }
  - { key: Key9,  mods: Command,       chars: "\x02\x39" }
  - { key: Up,       mods: Command, chars: "\x02\x1b\x5b\x41"            }   # move to another pane
  - { key: Down,     mods: Command, chars: "\x02\x1b\x5b\x42"            }
  - { key: Right,    mods: Command, chars: "\x02\x1b\x5b\x43"            }
  - { key: Left,     mods: Command, chars: "\x02\x1b\x5b\x44"            }
# .tmux.conf

# Necessary for using original color scheme in e.g. emacs
set-option -g default-terminal screen-256color

# Enable mouse
set-option -g mouse on

# Do not show a prompt before killing a pane
bind-key x kill-pane

# Use 1-index for windows and panes
set -g base-index 1
setw -g pane-base-index 1

# Switch panes with arrow keys in combination with alacritty
bind -n M-Left select-pane -L
bind -n M-Right select-pane -R
bind -n M-Up select-pane -U
bind -n M-Down select-pane -D