Open9

Alacritty + Tmuxの環境構築メモ

okmokm

自分のメモがてら記録を残していく。
とりあえず大元のalacrittyとtmuxをインストール

# alacritty
brew install --cask alacritty
# tmux
brew install tmux
okmokm

alacrittyの設定をするためにyamlファイルを作成。しようと思ったら、yamlでconfigファイルを作るのはどうやらdeprecatedしたらしいので、tomlファイルで色んな先人達の記事をありがたくかいつまんで、とりあえず作成する。

また、設定ファイルは.configに作りたかったので、ディレクトリを用意し、その配下に作成。
各種設定項目はこのリンクを参考
https://alacritty.org/config-alacritty.html

.config/alacritty/alacritty.toml
live_config_reload = true

[window]
dimensions = { columns = 200, lines = 60 }
padding = { x = 8, y = 4 }
opacity = 0.85

[cursor]
style = "Beam"

[scrolling]
history = 100000
multiplier = 3

[font]
normal = { family = "Hack Nerd Font", style = "Regular" }
bold = { family = "Hack Nerd Font", style = "Bold" }
italic = { family = "Hack Nerd Font", style = "Italic" }
bold_italic = { family = "Hack Nerd Font", style = "Bold Italic" }
size = 14.0
offset = { x = 0, y = 2 }
okmokm

alacrittyを手軽くカッコ良い見た目にしたいので、テーマをつかって色を設定する
https://github.com/alacritty/alacritty-theme?tab=readme-ov-file
このレポジトリを.config/alacrittyにクローンする

mkdir -p ~/.config/alacritty/themes
git clone https://github.com/alacritty/alacritty-theme ~/.config/alacritty/themes

そして、alacritty.tomlでimportするだけでテーマが変わってくれる

.config/alacritty/alacritty.toml
+ import = [
+   "~/.config/alacritty/themes/themes/zenburn.toml"
+ ]

okmokm

tmuxの設定をやってくぜ

tmuxの設定ファイルも.configの配下にtmuxディレクトリを作ってその中に、.tmux.confを作成する

.config/tmux/.tmux.conf
# ウィンドウを切り替える
bind -n S-left previous-window
bind -n S-right next-window

# マウス操作を有効にする
set-option -g mouse on

# prefix+r で設定のリロード
bind r source-file ~/.config/tmux/.tmux.conf \; display "Reloaded!"

set-window-option -g mode-keys vi

# PaneをVim-likeに移動する
bind -r k select-pane -U
bind -r j select-pane -D
bind -r h select-pane -L
bind -r l select-pane -R

# ステータスバーを上部に表示する
set -g status-position top
# checkhealth回避用
set -g escape-time 10
set -g focus-events on
okmokm

tmuxでクリップボードにコピーできるようにする

.config/tmux/.tmux.conf
# ウィンドウを切り替える
bind -n S-left previous-window
bind -n S-right next-window

# マウス操作を有効にする
set-option -g mouse on

# prefix+r で設定のリロード
bind r source-file ~/.config/tmux/.tmux.conf \; display "Reloaded!"

set-window-option -g mode-keys vi

# PaneをVim-likeに移動する
bind -r k select-pane -U
bind -r j select-pane -D
bind -r h select-pane -L
bind -r l select-pane -R

# ステータスバーを上部に表示する
set -g status-position top
# checkhealth回避用
set -g escape-time 10
set -g focus-events on

# コピーできるように
+ bind-key -T copy-mode-vi v send-keys -X begin-selection
+ bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle
+ bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "xsel -bi"
+ bind-key -T copy-mode-vi Enter send-keys -X copy-pipe-and-cancel "xsel -bi"
okmokm

なんかalacrittyからtmuxを起動時にconfを読み込まない。
chatGPTに詰問してみたところ、

tmuxはデフォルトでホームディレクトリ内の.tmux.confファイルを設定ファイルとして読み込みます。~/.config/tmux/.tmux.confに設定ファイルがある場合、tmuxは自動的にはこの場所を見に行きません。そのため、tmuxを起動する際に明示的に設定ファイルを指定する必要があります。

との、ことなので、明示的に指定するために以下を実行でできた

tmux -f ~/.config/tmux/.tmux.conf
okmokm

alacrittyとtmuxにtrue colorを設定する。色んな記事を見たら、みんなやってたのでやっておこうの精神。
https://namileriblog.com/mac/tmux/

この記事を大変参考にさせてもらい、実装してみる

/opt/homebrew/Cellar/ncurses/6.4/bin/infocmp -x xterm-256color > xterm-256color.src
sudo /usr/bin/tic -x xterm-256color.src

tmuxの起動

tmux

TERMの設定

export TERM=xterm-256color

だが、これでは自分の環境ではなんかうまくいかなかった。他の記事も参考にしてなんとか実装できた

.config/tmux/.tmux.conf
+ set -g default-terminal "tmux-256color"
+ set -ga terminal-overrides ",xterm-256color:Tc"
.config/alacritty/alacritty.toml
+ [env]
+ TERM = "tmux-256color"
okmokm

starshipがカッコ良さそうなので、入れてみる
もう、この記事でやってることをほぼパクった。大感謝https://namileriblog.com/terminal/terminal_setting_starship/

starshipの設定の詳細は以下のリンク。日本語も大体用意されている。
https://starship.rs/ja-jp/config/

アイコンは以下のリンクからコピーできる
https://www.nerdfonts.com/cheat-sheet

.config/starship.toml
# シェルプロンプトの間に空行を追加します
add_newline = true

format = """
[](fg:#7aa2f7)\
$os\
[ ](fg:#7aa2f7 bg:#1a1b26)\
$directory\
$git_branch\
$git_status\
$git_metrics\
[](fg:#1a1b26)\
$fill\
([](fg:#1a1b26)$nodejs[](fg:208 bg:#1a1b26)$package)\
([](fg:#1a1b26)$golang(bg:#1a1b26))\
\n$character\
"""

right_format = """
$cmd_duration
$time
"""

[os]
format = "[$symbol]($style)"
style = 'fg:#1a1b26 bg:#7aa2f7'
disabled = false
[os.symbols]
Macos = "  " # nf-fa-apple

# プロンプトの記号変更
[character]
success_symbol = "[󰀵 > ](bold green)"
error_symbol = "[ > ](bold red)"

[status]
style = "red"
symbol = "🔴"
format = '[\[$common_meaning$signal_name$maybe_int $status\]]($style) '
map_symbol = true
disabled = false

[directory]
truncation_length = 6
truncation_symbol = ' ' # nf-fa-folder_open
truncate_to_repo = false
home_symbol = ' ~' # nf-fa-home
style = 'fg:#7aa2f7 bg:#1a1b26'
read_only = ' 󰌾 ' # nf-md-lock
read_only_style = 'fg:#f7768e bg:#1a1b26'
format = '[$path]($style)[$read_only]($read_only_style)'

[git_branch]
symbol = '  ' # nf-fa-github_alt, nf-fa-code_fork
truncation_symbol = ''
style = 'fg:#7aa2f7 bg:#1a1b26'
format = '[  $symbol$branch(:$remote_branch)]($style)' # nf-pl-left_soft_divider

[git_status]
style = 'fg:#e0af68 bg:#1a1b26'
conflicted = '='
ahead = '⇡${count}'
behind = '⇣${count}'
diverged = '⇕'
up_to_date = '✓'
untracked = '?'
stashed = '$'
modified = '!${count}'
renamed = '»'
deleted = '✘'
format = '([\[$all_status$ahead_behind\]]($style))'

[git_metrics]
added_style = 'fg:#9ece6a bg:#1a1b26'
deleted_style = 'fg:#9ece6a bg:#1a1b26'
format = '[+$added/-$deleted]($deleted_style)'
disabled = false

[fill]
symbol = '─'
style = 'blue'

[nodejs]
symbol = " "
style = 'fg:#9ece6a bg:#1a1b26'
format = '[via $symbol($version )]($style)'

[golang]
symbol = "  󰟓 "
style = "fg:#79d4fd bg:#1a1b26"
format = '[via $symbol($version )]($style)'

[package]
format = '[ $symbol$version ]($style)'
# オレンジのカラーをfgに当てる
style = 'fg:#000000 bg:208'

[cmd_duration]
min_time = 1
style = 'fg:#e0af68'
format = "[   $duration]($style)" # nf-pl-right_soft_divider, nf-mdi-clock

[time]
disabled = false
style = 'fg:#73daca'
format = '[   $time]($style)' 
time_format = '%T'
utc_time_offset = '+9'

自分が使いそうなアプリケーションでformat部分は設定した。formatは()で囲むことで条件分岐ができるので、そのディレクトリに対象のものがない場合に、非表示にすることができた。
https://starship.rs/ja-jp/config/#条件付きフォーマット設定

nodeのアプリケーションの場合

goのアプリケーションの場合