How do I force a tmux window to be a given size
I want to force the windows in my tmux
session to be a particular size, regardless of the the size of my terminal. How can I do this?
Context
I am trying to record a tmux in asciinema as described here https://github.com/asciinema/asciinema/wiki/Recording-tmux-session (run asciinema on a tmux attach
command). However the display is too big, I want to force the size of the tmux window
.
Things that I have tried
I have a successful work around where I use a second view of the tmux session in mate-terminal -e 70x20
to force the window size… but this seems like a hack.
Trying to force the session size with -x
tmux new-session -x $X -y $Y -d
These options seem to be ignored (I’ve tried fiddling with the aggressive resize setting)
You probably need to have at least 3 panes open to occupy the unwanted areas. Try something like
tmux new-session ; split-window -h ; split-window -v ; resize-pane -x 70 -y 20
This should do what you want:
tmux new-session ; setw force-width 80 ; setw force-height 24 ; attach
or with $X
and $Y
, of course.
This is a bug in tmux, and has been fixed in the development version. The latest released version at this time is 3.2a, which does not have the fix.
It only appears to ignore the -x and -y options for a new detached session. The documentation says that these values will override the default-size settings for new windows, which suggested creating a new session, setting the default size, launching a new window, and then killing the initial window. That works. However, you can use the -x and -y options to override the default-size setting to avoid needing to adjust it, but you still have to create a new window. The problem is that the -x and -y modify the default-size for the session after the initial window has already been created.
tmux new-session -d -x $X -y $Y ; new-window ${MY_COMMAND} ; kill-window -t 0
So that will create a new session with the default size you want, then create a new window with the desired size running ${MY_COMMAND}, and finally kill the other window. This should work for running a command in a virtual terminal of whatever dimensions are required.