ターミナル環境構築
Alacritty、Starship、tmux、MonaspiceNe Nerd Font、Oh My Zshを組み合わせた、モダンで美しいターミナル環境を構築します。
構築の全体像
Section titled “構築の全体像”| ツール | 役割 |
|---|---|
| MonaspiceNe Nerd Font | プログラミング用フォント(アイコン対応) |
| Oh My Zsh | Zshの設定フレームワーク |
| 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でフォントをインストール”# MonaspiceNe Nerd Fontをインストールbrew install --cask font-monaspice-nerd-font1-2. インストール確認
Section titled “1-2. インストール確認”# インストールされたフォントを確認fc-list | grep -i monaspice以下のようなフォント名が表示されればOKです:
MonaspiceNe Nerd FontMonaspiceAr Nerd FontMonaspiceKr Nerd FontMonaspiceRn Nerd FontMonaspiceXe Nerd Font
✅ Step 1 チェックポイント
Section titled “✅ Step 1 チェックポイント”-
fc-list | grep -i monaspiceでフォントが表示される - フォントブックアプリで「Monaspace」が確認できる
Step 2: Oh My Zsh のインストール
Section titled “Step 2: Oh My Zsh のインストール”Zshの設定を簡単に管理できるフレームワークです。
2-1. Oh My Zshをインストール
Section titled “2-1. Oh My Zshをインストール”sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"インストール中に「デフォルトシェルをzshに変更しますか?」と聞かれたら y を入力します。
2-2. インストール確認
Section titled “2-2. インストール確認”# Oh My Zshがインストールされているか確認ls ~/.oh-my-zsh2-3. antidote(プラグインマネージャー)をインストール
Section titled “2-3. antidote(プラグインマネージャー)をインストール”brew install antidote2-4. プラグイン定義ファイルを作成
Section titled “2-4. プラグイン定義ファイルを作成”~/.zsh_plugins.txt を作成:
# oh-my-zsh 互換レイヤーgetantidote/use-omz
# oh-my-zsh プラグインohmyzsh/ohmyzsh path:plugins/brewohmyzsh/ohmyzsh path:plugins/git2-5. .zshrc に antidote 設定を追加
Section titled “2-5. .zshrc に antidote 設定を追加”~/.zshrc の最後に以下を追加:
# antidotesource "$(brew --prefix)/opt/antidote/share/antidote/antidote.zsh"antidote load✅ Step 2 チェックポイント
Section titled “✅ Step 2 チェックポイント”-
echo $ZSHで/Users/ユーザー名/.oh-my-zshが表示される - ターミナルを再起動してプロンプトが変わっている
Step 3: Alacritty のインストール
Section titled “Step 3: Alacritty のインストール”GPUアクセラレーションを活用した高速なターミナルエミュレータです。
3-1. Homebrewでインストール
Section titled “3-1. Homebrewでインストール”brew install --cask alacritty3-2. 設定ディレクトリを作成
Section titled “3-2. 設定ディレクトリを作成”mkdir -p ~/.config/alacritty3-3. 作業ディレクトリを作成
Section titled “3-3. 作業ディレクトリを作成”Alacritty起動時にtmuxが開くディレクトリを作成します:
mkdir -p ~/workspace3-4. 設定ファイルを作成
Section titled “3-4. 設定ファイルを作成”~/.config/alacritty/alacritty.toml を作成:
# Alacritty設定ファイル
# ==============================================================================# Window# ==============================================================================[window]decorations = "Transparent"opacity = 0.75padding = { 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 = truepost_processing = truepersist = falseregex = '''(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 = truemods = "Shift"3-5. Catppuccinテーマをダウンロード
Section titled “3-5. Catppuccinテーマをダウンロード”# Catppuccin Macchiatoテーマをダウンロードcurl -o ~/.config/alacritty/catppuccin-macchiato.toml \ https://raw.githubusercontent.com/catppuccin/alacritty/main/catppuccin-macchiato.toml3-6. Alacrittyを起動
Section titled “3-6. Alacrittyを起動”アプリケーションフォルダからAlacrittyを起動するか:
open -a Alacritty✅ Step 3 チェックポイント
Section titled “✅ Step 3 チェックポイント”- Alacrittyが起動する
- フォントがMonaspiceNeで表示されている
- 背景が半透明になっている(opacity設定)
Step 4: Starship のインストール
Section titled “Step 4: Starship のインストール”シェルに依存しない、カスタマイズ可能なプロンプトです。
4-1. Homebrewでインストール
Section titled “4-1. Homebrewでインストール”brew install starship4-2. Zshで有効化
Section titled “4-2. Zshで有効化”~/.zshrc の最後に以下を追加:
# Starship prompteval "$(starship init zsh)"Oh My Zshのテーマ
Starshipを使用する場合、Oh My Zshのテーマは無効化することをお勧めします。
~/.zshrc の ZSH_THEME を空文字列に設定:
ZSH_THEME=""4-3. 設定ファイルを作成
Section titled “4-3. 設定ファイルを作成”mkdir -p ~/.configtouch ~/.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 = 3truncate_to_repo = trueformat = "[$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 = 500format = "took [$duration](bold yellow)"4-4. 設定を反映
Section titled “4-4. 設定を反映”source ~/.zshrc✅ Step 4 チェックポイント
Section titled “✅ Step 4 チェックポイント”- プロンプトがStarshipのデザインに変わっている
- Gitリポジトリ内でブランチ名が表示される
- アイコン(、など)が正しく表示される
Step 5: tmux のインストール
Section titled “Step 5: tmux のインストール”ターミナルを複数のペインやウィンドウに分割できるツールです。
5-1. Homebrewでインストール
Section titled “5-1. Homebrewでインストール”brew install tmux5-2. 設定ファイルを作成
Section titled “5-2. 設定ファイルを作成”~/.tmux.conf を作成:
# プレフィックスキーをCtrl+aに変更(デフォルトはCtrl+b)set -g prefix C-aunbind C-bbind 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 -Lbind j select-pane -Dbind k select-pane -Ubind l select-pane -R
# ウィンドウ番号を1から開始set -g base-index 1setw -g pane-base-index 1
# ウィンドウを閉じたときに番号を詰めるset -g renumber-windows on
# ステータスバーの設定set -g status-position bottomset -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!"5-3. tmuxを起動
Section titled “5-3. tmuxを起動”tmux5-4. 基本的なキーバインド
Section titled “5-4. 基本的なキーバインド”| 操作 | キーバインド |
|---|---|
| プレフィックス | Ctrl + a |
| 縦分割 | Ctrl + a → | |
| 横分割 | Ctrl + a → - |
| ペイン移動 | Ctrl + a → h/j/k/l |
| 新しいウィンドウ | Ctrl + a → c |
| ウィンドウ切り替え | Ctrl + a → 数字 |
| デタッチ | Ctrl + a → d |
| 設定リロード | Ctrl + a → r |
5-5. tmuxプラグインマネージャー(オプション)
Section titled “5-5. tmuxプラグインマネージャー(オプション)”# TPM(Tmux Plugin Manager)をインストールgit clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm~/.tmux.conf の最後に追加:
# プラグイン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 + a → I
✅ Step 5 チェックポイント
Section titled “✅ Step 5 チェックポイント”-
tmuxコマンドで起動できる -
Ctrl + a→|で画面が縦分割される - ステータスバーが表示されている
- マウスでペインのリサイズができる
すべての設定が完了したら、以下を確認してください。
環境確認コマンド
Section titled “環境確認コマンド”# 各ツールのバージョン確認alacritty --versionstarship --versiontmux -Vecho $ZSH
# フォント確認fc-list | grep -i monaspice | head -3- Alacrittyを起動
- tmuxを開始(
tmux) - Starshipのプロンプトが表示されることを確認
- アイコンが正しく表示されることを確認
- ペイン分割(
Ctrl + a→|)が動作することを確認
トラブルシューティング
Section titled “トラブルシューティング”アイコンが文字化けする
Section titled “アイコンが文字化けする”- Alacrittyのフォント設定を確認
MonaspiceNe Nerd Fontが正しく指定されているか確認
Starshipが反映されない
Section titled “Starshipが反映されない”source ~/.zshrcを実行~/.zshrcの最後にeval "$(starship init zsh)"があるか確認
tmuxの色がおかしい
Section titled “tmuxの色がおかしい”~/.tmux.confのdefault-terminal設定を確認- Alacrittyの設定でTrue Colorが有効になっているか確認