tmux で複数のセッションを移動する
この記事は ターミナルマルチプレクサ Advent Calendar 2011 : ATND の9日目です。
8日目は、matsuu さんの tmuxで複数のペインに対して一斉に同じ文字を入力する - Dマイナー志向 でした。
今日は tmux で複数のセッションを移動するための switch-client というコマンドの紹介です。
switch-client [-lnp] [-c target-client] [-t target-session]
(alias: switchc)
Switch the current session for client target-client to target-session. If -l, -n or -p is used, the client is moved to the last, next or previous
session respectively.
:ls 0: 15 windows (created Tue Dec 6 22:49:51 2011) [181x59] 1: 3 windows (created Wed Dec 7 00:54:51 2011) [181x59] 2: 1 windows (created Wed Dec 7 02:03:36 2011) [181x59] 3: 4 windows (created Wed Dec 7 02:03:47 2011) [181x59]
こんな感じのセッションがある時に、switch-client を使うとセッション間での移動が可能になります。
:switch-client -t n # 移動したい session の番号 :switch-client -l # 最後の (直前に選択されていた) セッションへ移動します。 :switch-client -n # セッションを次のセッションへ移動します。 :switch-client -p # セッションを前のセッションへ移動します。
CHANGES を見ると、tmux 0.1 の頃から、switch-client はあったようです。
16 November 2007 略... * (nicm) switch-client command to switch client between different sessions. This is pretty cool: $ tmux bind q switch 0 $ tmux bind w switch 1 Then you can switch between sessions 0 and 1 with a key :-).
そして tmux 1.4 から switch-client に -[lnp] オプションが追加されたので
セッションの選択が番号を意識せずに、移動しやすくなりました。
bind-key ( switch-client -p bind-key ) switch-client -n bind-key L switch-client -l
デフォルトのキーバインド (tmux 1.5) は↑ですが、
僕は下のような設定にしています。
bind-key N switch-client -n bind-key P switch-client -p
session がこんなに簡単に切り替えられると、夢が広がります。*1
window 開きすぎ症候群の人や、session を手塩にかけて大切に育てる人には便利になると思います!
*1:screen にはこれと同じようなコマンドはあるのでしょうか?