AlacrittyをMacとzsh環境に導入する | 爆速ターミナル

Mac + zshに爆速ターミナル **Alacritty** を導入する方法をメモします。

# 環境
OC: macOS 10.15.6
シェル: zsh

## Alacrittyとは

Alacrittyとは、Rustで作られた端末エミュレータ。「（動画で言うところの）4k、5kのような高解像度ディスプレイでtmuxを起動し、vimを開いてコーディングしている時の画面描画の遅さだった」と言う理由から、開発を進めたみたいです。
https://jwilm.io/blog/announcing-alacritty/
[GitHub](https://github.com/alacritty/alacritty)

## Alacrittyをbrewでインストール

```
$ brew cask install alacritty
```

```
$ cd ~
$ mkdir -p .config/alacritty
$ touch .config/alactirry/alacritty.yml
```

## tmuxをbrewでインストール

```
$ brew install tmux
```

## tpm (tmux plugin manager) をclone

```
$ git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
```

## clipboardをbrewでインストール

```
$ brew install reattach-to-user-namespace
```

## alacritty.ymlを編集

```/alacritty/alacritty.yml 
env:
  TERM: xterm-256color
​
window:
  dimensions:
    columns: 160
    lines: 48
​
  padding:
    x: 2
    y: 2
​
  dynamic_padding: false
​
  decorations: full
​
  startup_mode: Windowed
​
scrolling:
  history: 10000
​
  multiplier: 3
​
  auto_scroll: false
​
tabspaces: 4
​
font:
  normal:
    family: Hack Nerd Font
    style: Regular
​
  bold:
    family: Hack Nerd Font
    style: Bold
​
  italic:
    family: Hack Nerd Font
    style: Regular Italic
​
  size: 11.0
​
  offset:
    x: 0
    y: 0
​
  glyph_offset:
    x: 0
    y: 0
​
  use_thin_strokes: true
​
draw_bold_text_with_bright_colors: true
​
# Colors (Challenger Deep)
colors:
  # Default colors
  primary:
    background: '0x1e1c31'
    foreground: '0xcbe1e7'
  # Colors the cursor will use if `custom_cursor_colors` is true
  cursor:
    text: '0xff271d'
    cursor: '0xfbfcfc'
  # Normal colors
  normal:
    black:   '0x141228'
    red:     '0xff5458'
    green:   '0x62d196'
    yellow:  '0xffb378'
    blue:    '0x65b2ff'
    magenta: '0x906cff'
    cyan:    '0x63f2f1'
    white:   '0xa6b3cc'
  # Bright colors
  bright:
    black:   '0x565575'
    red:     '0xff8080'
    green:   '0x95ffa4'
    yellow:  '0xffe9aa'
    blue:    '0x91ddff'
    magenta: '0xc991e1'
    cyan:    '0xaaffe4'
    white:   '0xcbe3e7'
​
background_opacity: 0.8
​
mouse_bindings:
  - { mouse: Middle, action: PasteSelection }
​
mouse:
  double_click: { threshold: 300 }
  triple_click: { threshold: 300 }
​
  hide_when_typing: false
​
  url:
    launcher: open
    modifiers: None
​
selection:
  semantic_escape_chars: ",│`|:\"' ()[]{}<>"
​
  save_to_clipboard: true 
​
dynamic_title: true
​
cursor:
  style: Block
  unfocused_hollow: false
​
live_config_reload: true
​
shell:
  program: /usr/local/bin/fish
  args:
    - --login
​
working_directory: None
​
enable_experimental_conpty_backend: false
​
alt_send_esc: true
​
debug:
  render_timer: false
​
  persistent_logging: false
​
  log_level: Warn
​
  print_events: false
​
  ref_test: false
​
key_bindings:
  - { key: V,        mods: Command, action: Paste                        }
  - { key: C,        mods: Command, action: Copy                         }
  - { key: Q,        mods: Command, action: Quit                         }
  - { key: N,        mods: Command, command: { program: "open", args: ["-nb", "io.alacritty"] } }
  - { key: Home,                    chars: "\x1bOH",   mode: AppCursor   }
  - { key: Home,                    chars: "\x1b[H",   mode: ~AppCursor  }
  - { key: End,                     chars: "\x1bOF",   mode: AppCursor   }
  - { key: End,                     chars: "\x1b[F",   mode: ~AppCursor  }
  - { key: Key0,     mods: Command, action: ResetFontSize                }
  - { key: Equals,   mods: Command, action: IncreaseFontSize             }
  - { key: Minus,    mods: Command, action: DecreaseFontSize             }
  - { key: PageUp,   mods: Shift,   chars: "\x1b[5;2~"                   }
  - { key: PageUp,   mods: Control, chars: "\x1b[5;5~"                   }
  - { key: PageUp,                  chars: "\x1b[5~"                     }
  - { key: PageDown, mods: Shift,   chars: "\x1b[6;2~"                   }
  - { key: PageDown, mods: Control, chars: "\x1b[6;5~"                   }
  - { key: PageDown,                chars: "\x1b[6~"                     }
  - { key: Tab,      mods: Shift,   chars: "\x1b[Z"                      }
  - { key: Back,                    chars: "\x7f"                        }
  - { key: Back,     mods: Alt,     chars: "\x1b\x7f"                    }
  - { key: Insert,                  chars: "\x1b[2~"                     }
  - { key: Delete,                  chars: "\x1b[3~"                     }
  - { key: Left,     mods: Shift,   chars: "\x1b[1;2D"                   }
  - { key: Left,     mods: Control, chars: "\x1b[1;5D"                   }
  - { key: Left,     mods: Alt,     chars: "\x1b[1;3D"                   }
  - { key: Left,                    chars: "\x1b[D",   mode: ~AppCursor  }
  - { key: Left,                    chars: "\x1bOD",   mode: AppCursor   }
  - { key: Right,    mods: Shift,   chars: "\x1b[1;2C"                   }
  - { key: Right,    mods: Control, chars: "\x1b[1;5C"                   }
  - { key: Right,    mods: Alt,     chars: "\x1b[1;3C"                   }
  - { key: Right,                   chars: "\x1b[C",   mode: ~AppCursor  }
  - { key: Right,                   chars: "\x1bOC",   mode: AppCursor   }
  - { key: Up,       mods: Shift,   chars: "\x1b[1;2A"                   }
  - { key: Up,       mods: Control, chars: "\x1b[1;5A"                   }
  - { key: Up,       mods: Alt,     chars: "\x1b[1;3A"                   }
  - { key: Up,                      chars: "\x1b[A",   mode: ~AppCursor  }
  - { key: Up,                      chars: "\x1bOA",   mode: AppCursor   }
  - { key: Down,     mods: Shift,   chars: "\x1b[1;2B"                   }
  - { key: Down,     mods: Control, chars: "\x1b[1;5B"                   }
  - { key: Down,     mods: Alt,     chars: "\x1b[1;3B"                   }
  - { key: Down,                    chars: "\x1b[B",   mode: ~AppCursor  }
  - { key: Down,                    chars: "\x1bOB",   mode: AppCursor   }
  - { key: F1,                      chars: "\x1bOP"                      }
  - { key: F2,                      chars: "\x1bOQ"                      }
  - { key: F3,                      chars: "\x1bOR"                      }
  - { key: F4,                      chars: "\x1bOS"                      }
  - { key: F5,                      chars: "\x1b[15~"                    }
  - { key: F6,                      chars: "\x1b[17~"                    }
  - { key: F7,                      chars: "\x1b[18~"                    }
  - { key: F8,                      chars: "\x1b[19~"                    }
  - { key: F9,                      chars: "\x1b[20~"                    }
  - { key: F10,                     chars: "\x1b[21~"                    }
  - { key: F11,                     chars: "\x1b[23~"                    }
  - { key: F12,                     chars: "\x1b[24~"                    }
  - { key: F1,       mods: Shift,   chars: "\x1b[1;2P"                   }
  - { key: F2,       mods: Shift,   chars: "\x1b[1;2Q"                   }
  - { key: F3,       mods: Shift,   chars: "\x1b[1;2R"                   }
  - { key: F4,       mods: Shift,   chars: "\x1b[1;2S"                   }
  - { key: F5,       mods: Shift,   chars: "\x1b[15;2~"                  }
  - { key: F6,       mods: Shift,   chars: "\x1b[17;2~"                  }
  - { key: F7,       mods: Shift,   chars: "\x1b[18;2~"                  }
  - { key: F8,       mods: Shift,   chars: "\x1b[19;2~"                  }
  - { key: F9,       mods: Shift,   chars: "\x1b[20;2~"                  }
  - { key: F10,      mods: Shift,   chars: "\x1b[21;2~"                  }
  - { key: F11,      mods: Shift,   chars: "\x1b[23;2~"                  }
  - { key: F12,      mods: Shift,   chars: "\x1b[24;2~"                  }
  - { key: F1,       mods: Control, chars: "\x1b[1;5P"                   }
  - { key: F2,       mods: Control, chars: "\x1b[1;5Q"                   }
  - { key: F3,       mods: Control, chars: "\x1b[1;5R"                   }
  - { key: F4,       mods: Control, chars: "\x1b[1;5S"                   }
  - { key: F5,       mods: Control, chars: "\x1b[15;5~"                  }
  - { key: F6,       mods: Control, chars: "\x1b[17;5~"                  }
  - { key: F7,       mods: Control, chars: "\x1b[18;5~"                  }
  - { key: F8,       mods: Control, chars: "\x1b[19;5~"                  }
  - { key: F9,       mods: Control, chars: "\x1b[20;5~"                  }
  - { key: F10,      mods: Control, chars: "\x1b[21;5~"                  }
  - { key: F11,      mods: Control, chars: "\x1b[23;5~"                  }
  - { key: F12,      mods: Control, chars: "\x1b[24;5~"                  }
  - { key: F1,       mods: Alt,     chars: "\x1b[1;6P"                   }
  - { key: F2,       mods: Alt,     chars: "\x1b[1;6Q"                   }
  - { key: F3,       mods: Alt,     chars: "\x1b[1;6R"                   }
  - { key: F4,       mods: Alt,     chars: "\x1b[1;6S"                   }
  - { key: F5,       mods: Alt,     chars: "\x1b[15;6~"                  }
  - { key: F6,       mods: Alt,     chars: "\x1b[17;6~"                  }
  - { key: F7,       mods: Alt,     chars: "\x1b[18;6~"                  }
  - { key: F8,       mods: Alt,     chars: "\x1b[19;6~"                  }
  - { key: F9,       mods: Alt,     chars: "\x1b[20;6~"                  }
  - { key: F10,      mods: Alt,     chars: "\x1b[21;6~"                  }
  - { key: F11,      mods: Alt,     chars: "\x1b[23;6~"                  }
  - { key: F12,      mods: Alt,     chars: "\x1b[24;6~"                  }
  - { key: F1,       mods: Command, chars: "\x1b[1;3P"                   }
  - { key: F2,       mods: Command, chars: "\x1b[1;3Q"                   }
  - { key: F3,       mods: Command, chars: "\x1b[1;3R"                   }
  - { key: F4,       mods: Command, chars: "\x1b[1;3S"                   }
  - { key: F5,       mods: Command, chars: "\x1b[15;3~"                  }
  - { key: F6,       mods: Command, chars: "\x1b[17;3~"                  }
  - { key: F7,       mods: Command, chars: "\x1b[18;3~"                  }
  - { key: F8,       mods: Command, chars: "\x1b[19;3~"                  }
  - { key: F9,       mods: Command, chars: "\x1b[20;3~"                  }
  - { key: F10,      mods: Command, chars: "\x1b[21;3~"                  }
  - { key: F11,      mods: Command, chars: "\x1b[23;3~"                  }
  - { key: F12,      mods: Command, chars: "\x1b[24;3~"                  }
  - { key: D,        mods: Command,       chars: "\x01\x76" } 
  - { key: D,        mods: Command|Shift, chars: "\x01\x73" }
  - { key: W,        mods: Command,       chars: "\x01\x78" }
  - { key: H,        mods: Command,       chars: "\x01\x68" }
  - { key: J,        mods: Command,       chars: "\x01\x6a" }
  - { key: K,        mods: Command,       chars: "\x01\x6b" }
  - { key: L,        mods: Command,       chars: "\x01\x6c" }
  - { key: T,        mods: Command,       chars: "\x01\x63" }
  - { key: RBracket, mods: Command|Shift, chars: "\x01\x6e" }
  - { key: LBracket, mods: Command|Shift, chars: "\x01\x70" }
  - { key: Return,   mods: Command|Shift, chars: "\x01\x7a" }
  - { key: Key1,     mods: Command,       chars: "\x01\x31" }
  - { key: Key2,     mods: Command,       chars: "\x01\x32" }
  - { key: Key3,     mods: Command,       chars: "\x01\x33" }
  - { key: Key4,     mods: Command,       chars: "\x01\x34" }
  - { key: Key5,     mods: Command,       chars: "\x01\x35" }
  - { key: Key6,     mods: Command,       chars: "\x01\x36" }
  - { key: Key7,     mods: Command,       chars: "\x01\x37" }
  - { key: Key8,     mods: Command,       chars: "\x01\x38" }
  - { key: Key9,     mods: Command,       chars: "\x01\x39" }
  - { key: Left,     mods: Command,       chars: "\x01\x48" }
  - { key: Down,     mods: Command,       chars: "\x01\x4a" }
  - { key: Up,       mods: Command,       chars: "\x01\x4b" }
  - { key: Right,    mods: Command,       chars: "\x01\x4c" }
  - { key: C,        mods: Command,       chars: "\x01\x5b" }
 ```

## tmux.confを編集

```tmux.conf
# Set prefix key to c-f instead of default c-b unbind C-b
set -g prefix C-a
bind C-a send-prefix
set-option -g default-shell /usr/local/bin/fish
# set-option -g default-shell /bin/bash
# toogle last window by hitting again C-f
bind-key C-f last-window
# if multiple clients are attached to the same window, maximize it to the
# bigger one
set-window-option -g aggressive-resize
# Start windows and pane numbering with index 1 instead of 0
set -g base-index 1
setw -g pane-base-index 1
# re-number windows when one is closed
set -g renumber-windows on
# word separators for automatic word selection
setw -g word-separators ' @"=()[]_-:,.'
setw -ag word-separators "'"
# Show times longer than supposed
set -g display-panes-time 2000
# tmux messages are displayed for 6 seconds
set -g display-time 4000
# {n}vim compability
set -g default-terminal "screen-256color"
# Split horiziontal and vertical splits, instead of % and "
# Also open them in the same directory
bind-key v split-window -h -c '#{pane_current_path}'
bind-key s split-window -v -c '#{pane_current_path}'
# Pressing Ctrl+Shift+Left (will move the current window to the left. Similarly
# right. No need to use the modifier (C-b).
bind-key -n C-S-Left swap-window -t -1
bind-key -n C-S-Right swap-window -t +1
# Source file
unbind r
bind r source-file ~/.tmux.conf \; display "Reloaded!"
# Use vim keybindings in copy mode
setw -g mode-keys vi
# Update default binding of `Enter` and `Space to also use copy-pipe
unbind -T copy-mode-vi Enter
unbind -T copy-mode-vi Space
bind-key -T edit-mode-vi Up send-keys -X history-up
bind-key -T edit-mode-vi Down send-keys -X history-down
# setup 'v' to begin selection as in Vim
bind-key -T copy-mode-vi 'v' send-keys -X begin-selection
# copy text with `y` in copy mode
# bind-key -T copy-mode-vi 'y' send -X copy-selection-and-cancel\; run "tmux save -|pbcopy >/dev/null 2>&1"
bind-key -T copy-mode-vi 'y' send-keys -X copy-pipe-and-cancel "reattach-to-user-namespace pbcopy"
# copy text with mouse selection without pressing any key
bind-key -T copy-mode-vi MouseDragEnd1Pane send -X copy-selection-and-cancel\; run "tmux save -|pbcopy >/dev/null 2>&1"
# bind-key -T copy-mode-vi MouseDragEnd1Pane send -X copy-selection-and-cancel
# emacs key bindings in tmux command prompt (prefix + :) are better than
# vi keys, even for vim users
set -g status-keys emacs
# focus events enabled for terminals that support them
set -g focus-events on
# Sync panes (Send input to all panes in the window). When enabled, pane
# borders become red as an indication.
bind C-s if -F '#{pane_synchronized}' \
                     'setw synchronize-panes off; \
                      setw pane-active-border-style fg=colour63,bg=default; \
                      setw pane-border-format       " #P "' \
                   'setw synchronize-panes on; \
                    setw pane-active-border-style fg=red; \
                    setw pane-border-format       " #P - Pane Synchronization ON "'
# Faster command sequence
set -s escape-time 0
# Have a very large history
set -g history-limit 1000000
# Mouse mode on
set -g terminal-overrides 'xterm*:smcup@:rmcup@'
set -g mouse on
# Set title
set -g set-titles on
set -g set-titles-string "#T"
# Equally resize all panes
bind-key = select-layout even-horizontal
bind-key | select-layout even-vertical
# Resize panes
bind-key J resize-pane -D 10
bind-key K resize-pane -U 10
bind-key H resize-pane -L 10
bind-key L resize-pane -R 10
# Select panes 
# NOTE(arslan): See to prevent cycling https://github.com/tmux/tmux/issues/1158
bind-key j select-pane -D 
bind-key k select-pane -U 
bind-key h select-pane -L 
bind-key l select-pane -R 
# Disable confirm before killing
bind-key x kill-pane
set -g status "on"
set -g status-style "none"
set -g status-justify "centre"
set -g status-position "top"
set -g status-left-length "100"
set -g status-left-style "none"
set -g status-left "[#S]"
set -g status-right-length "100"
set -g status-right-style "none"
set -g status-right "#{sysstat_cpu} | #{sysstat_mem} | #{sysstat_swap} | #{sysstat_loadavg} | %Y/%m/%d(%a) %H:%M"
set -g @sysstat_cpu_color_low "colour076"
set -g @sysstat_cpu_color_medium "colour220"
set -g @sysstat_cpu_color_stress "colour160"
set -g @sysstat_mem_color_low "green"
set -g @sysstat_mem_color_medium "blue"
set -g @sysstat_mem_color_stress "cyan"
set -g pane-active-border-style fg="colour148"
set -g pane-border-style fg="colour240"
set -g message-command-style fg="colour231"
set -g message-style bg="colour240"
set -g message-style fg="colour231"
set -g message-command-style bg="colour240"
setw -g window-status-style fg="colour245"
setw -g window-status-style "none"
setw -g window-status-activity-style bg="colour236"
setw -g window-status-activity-style "none"
setw -g window-status-activity-style fg="colour148"
setw -g window-status-separator ""
setw -g window-status-style bg="colour236"
setw -g window-status-format "#I #W "
set -g @tpm_plugins '                   \
   tmux-plugins/tpm                     \
   tmux-plugins/tmux-open               \
   tmux-plugins/tmux-yank               \
   tmux-plugins/tmux-prefix-highlight   \
   samoshkin/tmux-plugin-sysstat        \
'
# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run  '~/.tmux/plugins/tpm/tpm'
```

cmd + D ==> ペイン縦分割
cmd + shift + D ==> ペイン水平分割
cmd + vimのキーバインディング(h,j,k,l) ==> ペイン間移動