LoginSignup
61
55

More than 5 years have passed since last update.

[Tmux] セッションを自動保存・リストア

Posted at

セッションを自動で保存し、macを再起動しても自動でtmuxを起動し、セッションをリストアできるようにします。
手順
1. tpmを導入
2. 自動保存・リストアのプラグインを導入

tpm (Tmux Plugin Manager)を導入

tmuxのためのプラグイン管理ツールです。
まずtpmをダウンロードします。

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

次の設定を.tmux.confに追加します。

~/.tmux.conf
#===================================
# tpm - Tmux Plugin Manager
#===================================

# Plugins
set -g @plugin 'tmux-plugins/tpm'

# Initialize TMUX plugin manager 
# (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'

起動中のtmuxから設定を反映します。

$ tmux source ~/.tmux.conf

自動保存・リストアのプラグインを導入

インストールはtpmを通して行います。次のプラグインを導入します。

tmux-resurrectはtmuxを保存・リストアするプラグイン。tmux-continuumは保存・リストアを自動化するプラグインです。(tmux-resurrect-autoはtmux-continuumの旧名です。)
先ほどの設定ファイルに、次を追記します。

~/.tmux.conf
# Plugins
set -g @plugin 'tmux-plugins/tmux-resurrect'
set -g @plugin 'tmux-plugins/tmux-continuum'

追記したら、prefix + Iでプラグインをtpmによりインストールします。

インストールが完了したら、tmux起動時に自動で保存されたセッションをリストアするように設定します。
この際、tmux-continuumの機能として、terminalの自動起動も利用してみます。
以下を.tmux.confに追加します。

~/.tmux.conf
#===================================
# Auto start tmux and restore
#===================================

# auto start terminal
set -g @continuum-boot 'on'
set -g @continuum-boot-options 'iterm'

# auto restore tmux
set -g @continuum-restore 'on'


以上で完了です。再起動すると自動でリストアされるはずです。

61
55
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
61
55