コンテンツにスキップ

ターミナル環境構築

Alacritty、Starship、tmux、MonaspiceNe Nerd Font、Oh My Zshを組み合わせた、モダンで美しいターミナル環境を構築します。

ツール役割
MonaspiceNe Nerd Fontプログラミング用フォント(アイコン対応)
Oh My ZshZshの設定フレームワーク
Alacritty高速なターミナルエミュレータ
Starshipカスタマイズ可能なプロンプト
tmuxターミナルマルチプレクサ

Step 1: Nerd Font(MonaspiceNe)のインストール

Section titled “Step 1: Nerd Font(MonaspiceNe)のインストール”

Starshipやtmuxでアイコンを表示するために、Nerd Font対応のフォントが必要です。

1-1. Homebrewでフォントをインストール

Section titled “1-1. Homebrewでフォントをインストール”
Terminal window
# MonaspiceNe Nerd Fontをインストール
brew install --cask font-monaspice-nerd-font
Terminal window
# インストールされたフォントを確認
fc-list | grep -i monaspice

以下のようなフォント名が表示されればOKです:

  • MonaspiceNe Nerd Font
  • MonaspiceAr Nerd Font
  • MonaspiceKr Nerd Font
  • MonaspiceRn Nerd Font
  • MonaspiceXe Nerd Font
  • fc-list | grep -i monaspice でフォントが表示される
  • フォントブックアプリで「Monaspace」が確認できる

Zshの設定を簡単に管理できるフレームワークです。

Terminal window
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

インストール中に「デフォルトシェルをzshに変更しますか?」と聞かれたら y を入力します。

Terminal window
# Oh My Zshがインストールされているか確認
ls ~/.oh-my-zsh

2-3. antidote(プラグインマネージャー)をインストール

Section titled “2-3. antidote(プラグインマネージャー)をインストール”
Terminal window
brew install antidote

2-4. プラグイン定義ファイルを作成

Section titled “2-4. プラグイン定義ファイルを作成”

~/.zsh_plugins.txt を作成:

# oh-my-zsh 互換レイヤー
getantidote/use-omz
# oh-my-zsh プラグイン
ohmyzsh/ohmyzsh path:plugins/brew
ohmyzsh/ohmyzsh path:plugins/git

~/.zshrc の最後に以下を追加:

Terminal window
# antidote
source "$(brew --prefix)/opt/antidote/share/antidote/antidote.zsh"
antidote load
  • echo $ZSH/Users/ユーザー名/.oh-my-zsh が表示される
  • ターミナルを再起動してプロンプトが変わっている

GPUアクセラレーションを活用した高速なターミナルエミュレータです。

Terminal window
brew install --cask alacritty
Terminal window
mkdir -p ~/.config/alacritty

Alacritty起動時にtmuxが開くディレクトリを作成します:

Terminal window
mkdir -p ~/workspace

~/.config/alacritty/alacritty.toml を作成:

# Alacritty設定ファイル
# ==============================================================================
# Window
# ==============================================================================
[window]
decorations = "Transparent"
opacity = 0.75
padding = { x = 16, y = 32 }
dynamic_padding = true
# ==============================================================================
# Font
# ==============================================================================
[font]
normal = { family = "MonaspiceNe Nerd Font", style = "Regular" }
size = 12.0
# ==============================================================================
# Terminal Shell(tmux自動起動)
# ==============================================================================
[terminal.shell]
program = "/bin/zsh"
args = [
"-l",
"-c",
"cd ~/workspace && (tmux a -t default || tmux new -s default)",
]
# ==============================================================================
# Theme(外部ファイルからインポート)
# ==============================================================================
[general]
import = [
"~/.config/alacritty/catppuccin-macchiato.toml"
]
# ==============================================================================
# Keyboard Bindings (tmux連携)
# ==============================================================================
# \u0002 = Ctrl+b (tmux prefix)
# 参考: https://www.joshmedeski.com/posts/macos-keyboard-shortcuts-for-tmux/
[keyboard]
bindings = [
# Cmd+T: 新しいtmuxウィンドウ (prefix + c)
{ key = "T", mods = "Command", chars = "\u0002c" },
# Cmd+D: ペイン縦分割 (prefix + %)
{ key = "D", mods = "Command", chars = "\u0002%" },
# Cmd+Shift+D: ペイン横分割 (prefix + ")
{ key = "D", mods = "Command|Shift", chars = "\u0002\"" },
# Cmd+W: ペインを閉じる (prefix + x)
{ key = "W", mods = "Command", chars = "\u0002x" },
# Cmd+1-9: ウィンドウ切り替え (prefix + 1-9)
{ key = "1", mods = "Command", chars = "\u00021" },
{ key = "2", mods = "Command", chars = "\u00022" },
{ key = "3", mods = "Command", chars = "\u00023" },
{ key = "4", mods = "Command", chars = "\u00024" },
{ key = "5", mods = "Command", chars = "\u00025" },
{ key = "6", mods = "Command", chars = "\u00026" },
{ key = "7", mods = "Command", chars = "\u00027" },
{ key = "8", mods = "Command", chars = "\u00028" },
{ key = "9", mods = "Command", chars = "\u00029" },
# Cmd+N: 次のウィンドウ (prefix + n)
{ key = "N", mods = "Command", chars = "\u0002n" },
# Cmd+P: 前のウィンドウ (prefix + p)
{ key = "P", mods = "Command", chars = "\u0002p" },
# Cmd+Shift+B: ペインを別ウィンドウに分離 (prefix + B)
{ key = "B", mods = "Command|Shift", chars = "\u0002B" },
# Cmd+矢印: ペイン移動 (prefix + 矢印)
{ key = "Left", mods = "Command", chars = "\u0002\u001b[D" },
{ key = "Right", mods = "Command", chars = "\u0002\u001b[C" },
{ key = "Up", mods = "Command", chars = "\u0002\u001b[A" },
{ key = "Down", mods = "Command", chars = "\u0002\u001b[B" },
# Shift+Enter: 改行文字を送信 (Claude Code等での改行挿入用)
{ key = "Return", mods = "Shift", chars = "\n" },
]
# ==============================================================================
# Hints (URLクリックで開く)
# ==============================================================================
[[hints.enabled]]
command = "open"
hyperlinks = true
post_processing = true
persist = false
regex = '''(ipfs:|ipns:|magnet:|mailto:|gemini://|gopher://|https://|http://|news:|file:|git://|ssh:|ftp://)[^\u0000-\u001F\u007F-\u009F<>"\s{-}\^⟨⟩`']+'''
[hints.enabled.binding]
key = "O"
mods = "Control|Shift"
[hints.enabled.mouse]
enabled = true
mods = "Shift"

3-5. Catppuccinテーマをダウンロード

Section titled “3-5. Catppuccinテーマをダウンロード”
Terminal window
# Catppuccin Macchiatoテーマをダウンロード
curl -o ~/.config/alacritty/catppuccin-macchiato.toml \
https://raw.githubusercontent.com/catppuccin/alacritty/main/catppuccin-macchiato.toml

アプリケーションフォルダからAlacrittyを起動するか:

Terminal window
open -a Alacritty
  • Alacrittyが起動する
  • フォントがMonaspiceNeで表示されている
  • 背景が半透明になっている(opacity設定)

シェルに依存しない、カスタマイズ可能なプロンプトです。

Terminal window
brew install starship

~/.zshrc最後に以下を追加:

Terminal window
# Starship prompt
eval "$(starship init zsh)"

Oh My Zshのテーマ

Starshipを使用する場合、Oh My Zshのテーマは無効化することをお勧めします。 ~/.zshrcZSH_THEME を空文字列に設定:

Terminal window
ZSH_THEME=""
Terminal window
mkdir -p ~/.config
touch ~/.config/starship.toml

~/.config/starship.toml に以下を記述:

# Starship設定ファイル
# プロンプトの形式
format = """
[┌─](bold blue)$directory$git_branch$git_status
[└─](bold blue)$character"""
# コマンド実行後に空行を追加
add_newline = true
# ディレクトリ表示
[directory]
style = "bold cyan"
truncation_length = 3
truncate_to_repo = true
format = "[$path]($style)[$read_only]($read_only_style) "
# Gitブランチ
[git_branch]
symbol = " "
style = "bold purple"
format = "on [$symbol$branch]($style) "
# Gitステータス
[git_status]
style = "bold red"
format = '([$all_status$ahead_behind]($style))'
# プロンプト文字
[character]
success_symbol = "[❯](bold green)"
error_symbol = "[❯](bold red)"
# Node.js
[nodejs]
symbol = " "
format = "[$symbol($version )]($style)"
# Python
[python]
symbol = " "
format = "[$symbol($version )]($style)"
# Rust
[rust]
symbol = " "
format = "[$symbol($version )]($style)"
# 実行時間
[cmd_duration]
min_time = 500
format = "took [$duration](bold yellow)"
Terminal window
source ~/.zshrc
  • プロンプトがStarshipのデザインに変わっている
  • Gitリポジトリ内でブランチ名が表示される
  • アイコン(、など)が正しく表示される

ターミナルを複数のペインやウィンドウに分割できるツールです。

Terminal window
brew install tmux

~/.tmux.conf を作成:

Terminal window
# プレフィックスキーをCtrl+aに変更(デフォルトはCtrl+b)
set -g prefix C-a
unbind C-b
bind C-a send-prefix
# マウス操作を有効化
set -g mouse on
# 256色対応
set -g default-terminal "tmux-256color"
set -ag terminal-overrides ",alacritty:RGB"
# ペイン分割のキーバインド(直感的に)
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
# ペイン移動をvim風に
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# ウィンドウ番号を1から開始
set -g base-index 1
setw -g pane-base-index 1
# ウィンドウを閉じたときに番号を詰める
set -g renumber-windows on
# ステータスバーの設定
set -g status-position bottom
set -g status-style 'bg=#1a1b26 fg=#c0caf5'
set -g status-left '#[fg=#7aa2f7,bold] #S '
set -g status-right '#[fg=#9ece6a]%Y-%m-%d #[fg=#7aa2f7]%H:%M '
set -g status-left-length 20
# アクティブウィンドウの強調
setw -g window-status-current-style 'fg=#1a1b26 bg=#7aa2f7 bold'
setw -g window-status-current-format ' #I:#W '
setw -g window-status-style 'fg=#a9b1d6'
setw -g window-status-format ' #I:#W '
# ペインの境界線
set -g pane-border-style 'fg=#414868'
set -g pane-active-border-style 'fg=#7aa2f7'
# 履歴の上限
set -g history-limit 10000
# エスケープキーの遅延を解消
set -sg escape-time 0
# 設定ファイルのリロード
bind r source-file ~/.tmux.conf \; display "Config reloaded!"
Terminal window
tmux
操作キーバインド
プレフィックスCtrl + a
縦分割Ctrl + a|
横分割Ctrl + a-
ペイン移動Ctrl + ah/j/k/l
新しいウィンドウCtrl + ac
ウィンドウ切り替えCtrl + a数字
デタッチCtrl + ad
設定リロードCtrl + ar

5-5. tmuxプラグインマネージャー(オプション)

Section titled “5-5. tmuxプラグインマネージャー(オプション)”
Terminal window
# TPM(Tmux Plugin Manager)をインストール
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm

~/.tmux.conf の最後に追加:

Terminal window
# プラグイン
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'
# TPMの初期化(この行は設定ファイルの最後に置く)
run '~/.tmux/plugins/tpm/tpm'

プラグインのインストール:Ctrl + aI

  • tmux コマンドで起動できる
  • Ctrl + a| で画面が縦分割される
  • ステータスバーが表示されている
  • マウスでペインのリサイズができる

すべての設定が完了したら、以下を確認してください。

Terminal window
# 各ツールのバージョン確認
alacritty --version
starship --version
tmux -V
echo $ZSH
# フォント確認
fc-list | grep -i monaspice | head -3
  1. Alacrittyを起動
  2. tmuxを開始(tmux
  3. Starshipのプロンプトが表示されることを確認
  4. アイコンが正しく表示されることを確認
  5. ペイン分割Ctrl + a|)が動作することを確認
  • Alacrittyのフォント設定を確認
  • MonaspiceNe Nerd Font が正しく指定されているか確認
  • source ~/.zshrc を実行
  • ~/.zshrc の最後に eval "$(starship init zsh)" があるか確認
  • ~/.tmux.confdefault-terminal 設定を確認
  • Alacrittyの設定でTrue Colorが有効になっているか確認