プラグイン・拡張
tmuxの機能を拡張するプラグインやツールを紹介します。
TPM(Tmux Plugin Manager)
TPMはtmuxのプラグイン管理ツールです。多くのプラグインはTPM経由でインストールできます。
TPMインストール
git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
.tmux.conf でTPMを初期化
# ~/.tmux.conf
# プラグインリスト
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
# TPM初期化(ファイル最後に記述)
run '~/.tmux/plugins/tpm/tpm'
プラグインのインストール
.tmux.confにset -g @plugin 'author/plugin-name'を追加~/.tmux.confを再読み込み(またはターミナル再起動)Ctrl+b I(大文字I)でインストール
プラグインの更新・削除
- 更新:
Ctrl+b U - 削除:.tmux.conf から削除後、
Ctrl+b alt+u
人気プラグイン
1. tmux-sensible(基本設定)
基本的で安全な設定をセットアップ。
set -g @plugin 'tmux-plugins/tmux-sensible'
2. tmux-resurrect(セッション復元)
ターミナル再起動時にセッション・ウィンドウ・ペインを復元。
set -g @plugin 'tmux-plugins/tmux-resurrect'
# 設定
set -g @resurrect-capture-pane-contents 'on'
set -g @resurrect-strategy-vim 'session'
キーバインド:
Ctrl+b Ctrl+s: セッション保存Ctrl+b Ctrl+r: セッション復元
3. tmux-continuum(自動保存)
tmux-resurrectの自動保存版。定期的にセッションを自動保存。
set -g @plugin 'tmux-plugins/tmux-continuum'
# 15分ごとに自動保存
set -g @continuum-save-interval '15'
# tmux起動時に前回のセッションを自動復元
set -g @continuum-restore 'on'
4. tmux-pain-control(ペイン操作改善)
ペイン分割とナビゲーションのキーバインドを改善。
set -g @plugin 'tmux-plugins/tmux-pain-control'
改善されたキーバインド:
Ctrl+b h/j/k/l: ペイン移動(Vimキー対応)Ctrl+b H/J/K/L: ペインリサイズ
5. tmux-yank(クリップボード連携)
Vim的なヤンク操作でクリップボードにコピー。
set -g @plugin 'tmux-plugins/tmux-yank'
キーバインド:
Ctrl+b [で開いたコピーモード内でy: コピーCtrl+b ]: ペースト
6. tmux-prefix-highlight(プレフィックス状態表示)
プレフィックスキー押下時にステータスバーで表示。
set -g @plugin 'tmux-plugins/tmux-prefix-highlight'
# ステータスバーに表示
set -g status-right '#{prefix_highlight} | %a %Y-%m-%d %H:%M'
7. tmux-cpu(CPU・メモリ表示)
ステータスバーにCPU使用率とメモリ使用率を表示。
set -g @plugin 'tmux-plugins/tmux-cpu'
# ステータスバーに表示
set -g status-right '#{cpu_fg_color}CPU: #{cpu_percentage} | %H:%M'
8. tmux-fingers(コピー便利化)
キーバインドでテキストをハイライト&コピー。
set -g @plugin 'tmux-plugins/tmux-fingers'
キーバインド:
Ctrl+b F: Fingersモード開始
スクリプト・ツール
tmuxp(プロジェクト環境管理)
YAML形式でプロジェクト環境を定義。
# インストール
pip install tmuxp
# プロジェクト設定ファイル
# ~/.config/tmuxp/myproject.yaml
session_name: myproject
windows:
- window_name: editor
panes:
- vim src/
- window_name: server
panes:
- npm start
- window_name: test
panes:
- npm test -- --watch
起動:
tmuxp load myproject
Zellij(代替ターミナルマルチプレクサー)
Rustで書かれた最新のターミナルマルチプレクサー。
brew install zellij
zellij
tmuxとは異なるキーバインドですが、機能豊富です。
プラグイン設定例
完全な設定例
# ~/.tmux.conf
# TPM プラグインリスト
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'
set -g @plugin 'tmux-plugins/tmux-pain-control'
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @plugin 'tmux-plugins/tmux-prefix-highlight'
set -g @plugin 'tmux-plugins/tmux-cpu'
# プラグイン設定
set -g @resurrect-capture-pane-contents 'on'
set -g @continuum-save-interval '15'
set -g @continuum-restore 'on'
# ステータスバーにプラグイン情報を表示
set -g status-right '#{cpu_fg_color}CPU: #{cpu_percentage} | #{prefix_highlight} | %H:%M'
# TPM初期化
run '~/.tmux/plugins/tpm/tpm'
カスタムスクリプト
Session快速作成スクリプト
#!/bin/bash
# ~/.tmux/new-session.sh
# FZFで過去のセッション・ディレクトリから選択
SESSION_DIR=$(find ~/projects -maxdepth 2 -type d | fzf)
if [ -z "$SESSION_DIR" ]; then
exit 1
fi
SESSION_NAME=$(basename "$SESSION_DIR")
tmux new-session -d -s "$SESSION_NAME" -c "$SESSION_DIR"
tmux attach -t "$SESSION_NAME"
使用方法:
chmod +x ~/.tmux/new-session.sh
~/.tmux/new-session.sh
注意点
- プラグイン数を絞る: 多すぎるプラグインは起動時間が長くなる
- バージョン確認: 古いtmuxではプラグインが動作しないことがある
- ドキュメント確認: 各プラグインのGitHubでインストール方法を確認