0

I have a tmux set-up where my top pane is always 2 rows big. Unfortunately every time the terminal gets resized, the proportions are completely reset and the top pane takes up much more space.

I created a binding in my .tmux.conf file that allows me to resize the pane by pressing F12: bind -n F12 resize-pane -t 0 -y 2

However, It'd like this to be done automatically on every resize event. Is there a way to do this somehow efficiently?

1 Answer 1

0

I tried the following on version 2.7 or so and it seemed to work. You can add a hook to run a tmux command on several events, and in particular it seems that window-layout-changed gets triggered when panes are resized. I tried the obvious

set-hook -g window-layout-changed 'resize-pane -t 0 -y 2'

but that created an infinite loop. Some events have an after version, but apparently there is no after-window-layout-changed event. (Earlier versions of tmux have a layout-changed event, but I couldn't get it to work).

So finally, I created a small shell script, myscript, in my PATH to check the current size of the pane and only resize it if necessary:

#!/bin/bash
ht=$(tmux display-message -p -t 0 '#{pane_height}')
if [ 2 != "$ht" ]
then tmux display-panes\; resize-pane -t 0 -y 2
fi

I added the display-panes just to see if the script was running. This seemed to work well with:

set-hook -g window-layout-changed 'run-shell myscript'

and even in the case where there was only pane 0 left (which was therefore un-resizable).

1
  • You're a gentleman, and a scholar!
    – Muppet
    Commented Jan 24, 2020 at 19:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .