LoginSignup
24
20

More than 5 years have passed since last update.

再起動前のtmux環境を復活させる

Last updated at Posted at 2017-06-13

再起動前のtmux環境を復活させる方法について記載

 1.Tmux Plugin Managerのインストール

リポジトリをクローン

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

.tmux.confに以下の内容を追加
(.tmux.confがなければ~/.tmux.confで作成)

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

# Other examples:
# set -g @plugin 'github_username/plugin_name'
# set -g @plugin 'git@github.com/user/plugin'
# set -g @plugin 'git@bitbucket.com/user/plugin'

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

設定の反映

$ tmux source ~/.tmux.conf

 2.tmux-resurrectのインストール

.tmux.confに以下の内容を追加

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

ターミナルで、tmux起動して、以下のコマンドでプラグインのインストール

(prefix) + I

アップデートは以下のコマンド

(prefix) + U

 3.tmux-resurrectの設定を追加

.tmux.confに以下の内容を追加

# resurrect
set -g @resurrect-strategy-vim 'session'

設定の反映

$ tmux source ~/.tmux.conf

 4.save、restore

以下のコマンドでsave

prefix + Ctrl-s

以下のコマンドでrestore

prefix + Ctrl-r

これで、再起動してもtmuxの設定が復活します。

捕捉
sshなどを表示していたコマンドをrestore時に再度行う場合は、
.tmux.confに以下の内容を追加

set -g @resurrect-processes 'mysql ssh php'

terminal起動時に、tmuxを起動する。
.bash_profileや.zshrcに以下を追記(nameは任意のsession名)

# 初回シェル時のみ tmux実行
if [ $SHLVL = 1 ]; then
  tmux a -t name
fi

参考
https://github.com/tmux-plugins/tpm
https://github.com/tmux-plugins/tmux-resurrect

24
20
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
24
20