【tmux】プラグインを使ってみる

スポンサーリンク

はじめに

tmuxでのプラグインの導入方法と参考用に現在利用しているプラグインとその設定を紹介したいと思います。

tmuxの基礎的な部分は下記で解説しています。

【入門】tmux始めてみる
はじめに tmuxについて、基本的なことを理解して使えるようになるまでを解説していこうと思います。 tmuxとは tmuxとは、端末多重化ソフトウェア(Terminal Multiplexer)です。 端末多重化ソフトウェアと言ってもわかり...

tmuxのプラグイン管理

tmuxではプラグインを利用することで見た目や操作方法をカスタマイズしやすくなります。

tpm(Tmux Plugin Manager)を利用することで、プラグインの管理がしやすくなります。tmuxでプラグインを利用する場合はまずtpmを導入するところから始まります。

tpm(Tmux Plugin Manager)の導入

まずはtpmをgithubからクローンします。

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

tpmを利用するには.tmux.confで以下のように記述します。

# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'

# tpmの初期化(tmux.confの下の方に記述する)
run '~/.tmux/plugins/tpm/tpm'

.tmux.confを変更したので読み込みます。

tmux source ~/.tmux.conf

これでプラグインを追加する準備はできました。

プラグインの追加

具体例として、以下のプラグインを追加してみます。

GitHub - tmux-plugins/tmux-pain-control: standard pane key-bindings for tmux
standard pane key-bindings for tmux. Contribute to tmux-plugins/tmux-pain-control development by creating an account on GitHub.

まずは.tmux.confにプラグインを追加します。

# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'

# プラグインを追加
set -g @plugin 'tmux-plugins/tmux-pain-control'

# tpmの初期化(tmux.confの下の方に記述する)
run '~/.tmux/plugins/tpm/tpm'

.tmux.confを変更したら、prefix + Iでプラグインの取得できます。

便利そうなプラグインは以下でまとめられているので、参照してください。

GitHub - rothgar/awesome-tmux: A list of awesome resources for tmux
A list of awesome resources for tmux. Contribute to rothgar/awesome-tmux development by creating an account on GitHub.

設定

参考程度に現在私の利用しているプラグインと.tmux.confを紹介します。

  • tpm:tmuxのプラグインマネージャー
  • tmux-sensible:おすすめオプションを設定してくれる
  • tmux-yank:tmuxからクリップボードにコピー可能に
  • tmux-copycat:検索を便利に
  • tmux-pain-control:vimっぽいペインの移動を可能に
  • dracula/tmux:draculaのテーマ
GitHub - tmux-plugins/tpm: Tmux Plugin Manager
Tmux Plugin Manager. Contribute to tmux-plugins/tpm development by creating an account on GitHub.
GitHub - tmux-plugins/tmux-sensible: basic tmux settings everyone can agree on
basic tmux settings everyone can agree on. Contribute to tmux-plugins/tmux-sensible development by creating an account on GitHub.
GitHub - tmux-plugins/tmux-yank: Tmux plugin for copying to system clipboard. Works on OSX, Linux and Cygwin.
Tmux plugin for copying to system clipboard. Works on OSX, Linux and Cygwin. - GitHub - tmux-plugins/tmux-yank: Tmux plugin for copying to system clipboard. Wor...
GitHub - tmux-plugins/tmux-copycat: A plugin that enhances tmux search
A plugin that enhances tmux search. Contribute to tmux-plugins/tmux-copycat development by creating an account on GitHub.
GitHub - tmux-plugins/tmux-pain-control: standard pane key-bindings for tmux
standard pane key-bindings for tmux. Contribute to tmux-plugins/tmux-pain-control development by creating an account on GitHub.
GitHub - dracula/tmux: 🧛🏻‍♂️ Dark theme for tmux
🧛🏻‍♂️ Dark theme for tmux. Contribute to dracula/tmux development by creating an account on GitHub.

.tmux.confは以下のようになっています。

# ---------------------------------------------------------
# plugin
# ---------------------------------------------------------

set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-copycat'
set -g @plugin 'tmux-plugins/tmux-pain-control'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-yank'
set -g @plugin 'dracula/tmux'
set -g @dracula-plugins "battery cpu-usage ram-usage weather time"

# ---------------------------------------------------------
# basic
# ---------------------------------------------------------

# tmux起動時のシェルをzshに
set-option -g default-shell /bin/zsh

# 256色表示可能に変更
set-option -g default-terminal screen-256color
set -g terminal-overrides 'xterm:colors=256'

# PrefixをCtrl-qに変更
set -g prefix C-q
unbind C-b

# ---------------------------------------------------------
# mapping
# ---------------------------------------------------------

# .tmux.confの読み込み
bind-key r source-file ~/.tmux.conf\; display-message "$HOME/.tmux.conf reloaded!"

# ---------------------------------------------------------
# copy mode
# ---------------------------------------------------------

setw -g mode-keys vi

# ---------------------------------------------------------
# status bar
# ---------------------------------------------------------

# dracula options
set -g @dracula-left-icon-padding 2
set -g @dracula-show-location false
set -g @dracula-show-fahrenheit false
set -g @dracula-show-timezone false
set -g @dracula-show-flags true
set -g @dracula-military-time true

# ---------------------------------------------------------
# initialize tmux plugin manager
# ---------------------------------------------------------

run '~/.tmux/plugins/tpm/tpm'

見た目は以下のような感じになります。

ちなみに、左側のコマンドはbrew install neofetchで取得でき、右下の時計はprefix + tで表示できます。

参考

タイトルとURLをコピーしました