I'm triyng to setup a tmux session from a bash script, without using any session manager like tmuxinator/tmuxp/...
If I run this code
#!/bin/sh
tmux \
new '/path/to/a/script.sh' \; \
splitw -v '/path/to/another/program' \; \
selectp -U \; \
resizep -y 4 \;
it works, except for one thing: according to man tmux
I expect it to resize the top pane to 4 lines but it resizes it to a variable number of lines that depends on the size of the terminal window (it is not necessarily 4 lines and it is not 4% of the window height).
If I remove the resizep line
#!/bin/sh
tmux \
new '/path/to/a/script.sh' \; \
splitw -v '/path/to/another/program' \; \
selectp -U \;
and then from inside the session I manually run the :resizep -y 4
tmux command, then it resizes it effectively to 4 lines.
Does anybody know why it happens and what can I do to fix it?
According to man tmux
Specs
OS: Arch Linux
WM: dwm (suckless)
Terminal: ts (suckless)
Shell: bash
EDIT: I execute this bash script in a ts/bash shell, so at the moment I execute it, the shell window already exists with its width and height.
Ok! Finally I solved it (after almost an year) and it was so simple...
I just added a name for the session and specified the session name and window number in the resizep command.
I paste here the code, so maybe it will help someone in the future.
tmux \
new '/path/to/a/script.sh' \; \
rename "session_name" \; \
splitw -v '/path/to/another/script.sh' \; \
selectp -U \; \
resizep -t "session_name:1" -y 4 \;
Notice the 1
in the session name. Normally it would be 0
but in my .tmuxrc I have set set -g base-index 1