LoginSignup
3

More than 5 years have passed since last update.

tmuxのpaneを兄弟だけ均等に並べる

Posted at

tmuxのpaneは複雑なレイアウトを構成できて便利なのですが、paneを均等に並べるのが横一列とか縦一列、タイリングなどと大雑把な感じで、アクティブなpaneが属するカラム内だけ均等分割したい、みたいなことは実現が難しいです。そこで、これを実現する方法を考えてみましょう。

tmuxのwindowの分割状況、paneの配置などの情報は tmux display -p "#{window_visible_layout}" で以下のような文字列として得ることができます。

x> tmux display -p "#{window_visible_layout}"
a158,80x64,0,0[81x16,0,0{40x16,0,0,108,40x16,41,0,127},81x15,0,17,126,81x32,0,33{31x32,0,33[31x16,0,33,122,31x15,0,50,128],49x32,32,33,123}]  

pane情報につづき、[ ... ] で縦分割、{ ... } で横分割という感じの入れ子になってますね。この文字列のparserを作りました。

これを使って、

  • activeなpaneの兄弟だけ均等分割(同軸方向の均等分割)
  • activeなpaneの親の兄弟だけ均等分割(逆軸方向の均等分割)

を実現するスクリプトを作りました。

以下のように ~/.tmux.confbind して使います。

bind * run-shell "/path/to/tmux_even_pane 0"
bind + run-shell "/path/to/tmux_even_pane 1"

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
3