it seems my requests are simply ignored
It's not clear what requests are ignored. Your script kinda works for me, nothing seems to be ignored if I run it fresh, without tmux server already running. With tmux server already running there are problems:
- the session may already exist and someone may be (actively) using it,
- the window may already exist,
- your
split-windowcommands may target some other (pre-existing) window.
It seems to me that some layouts are simply not allowed.
If your goal is to work with the layout you already have and get to the desired layout by doing something more after, then it will be difficult because you cannot easily get the desired top-right or the bottom-right pane after the whole left "33%" column is split to two "50%" panes. You need to split in a different order.
One way to learn what the order may be is to draw the layout on a piece of paper and cut it with scissors with straight cuts that go through, so each cut divides the current piece into two smaller ones. A possible scheme for your desired layout is like this:
+---------------------+
| 1 |
|22222221 |
| 3 1 |
| 3 1#############|
| 3 1 |
|22222221 |
| 1 |
+---------------------+
The numbers indicate in what order you need to cut. The cut marked with # represents multiple cuts in the right column, you can make them in any order after 1, before or after 2 or 3. These # cuts are not important to the issue. The important thing is you need to make the two 2 cuts (in any order) after 1 and before 3. Your script performs the 3 cut without making 2 and then there is no straightforward way to get what you want.
There is split-window -f, it creates a new pane spanning the full window height or full window width, instead of splitting a single pane. While it brings some flexibility and allows creating panes in yet different order, it won't help you get the desired layout from your achieved layout; nor it will make more layouts possible.
For comparison, this is a truly impossible layout, I think:
+---------------------+
| # |
| # |
| ##############|
| | | |
| | | |
|---------------| |
| | |
+---------------------+
In reality you can cut it with scissors but not with tmux, because at least the first cut with scissors needs to bend to create two separate pieces of paper. An example first cut is drawn with # characters. You can interpret it as two cuts that are not "through", so for tmux this interpretation changes nothing, it's still impossible.
This is an example script that works for me in tmux 2.3. Remarks and improvements are listed as notes below the code; please read them before you run the script.
#!/bin/sh
session="$USER"
window="$session:1"
tmux -2 new-session -d -s "$session" 'echo "step -1"; bash'
tmux new-window -t "$window" -n 'Logs' 'echo "step 0"; bash' || exit
tmux split-window -t "$window" -h -p 67 -d 'echo "step 1"; bash'
tmux split-window -t "$window" -v -p 10 -b -d 'echo "step 2a"; bash'
tmux split-window -t "$window" -v -p 22 -d 'echo "step 2b"; bash'
tmux split-window -t "$window" -h -p 50 'echo "step 3"; bash'
tmux split-window -t "$window.{top-right}" -v -p 55 -d
tmux split-window -t "$window.{top-right}" -v -p 64
tmux select-pane -t "$window.{bottom-right}"
tmux split-window -t "$window" -v -p 67
tmux split-window -t "$window" -v -p 50
tmux select-window -t "$window"
# Attach to session
tmux -2 attach-session -t "$session"
Notes:
- The shebang is
/bin/sh, no need for Bash here. - Get used to double-quoting variables. It's way better to habitually quote regardless if you need it than forget to quote when it makes a real difference.
- I used lowercase names for variables.
- If window cannot be created, the script exits.
- Each
split-windowtargets the right window. If the session existed or someone attached in the meantime and changed the window, the current window would not be what you assume. To be even more robust eachsplit-windowshould target a respective pane explicitly. Note thatselect-panebeforesplit-window(or beforeresize-paneas in your script) is not really robust in a general setup where many clients can interact with the same tmux server: some other client (user or script) could select another pane between these two commands. - I do not resize panes. I create them with proper percentages in the first place. The
-poption I use works in my oldish tmux. The documentation tells me the newer syntax is likesplit-window -l 20%andresize-panecan work with percentages as well. I don't know if the newest tmux understandssplit-window -p. The documentation doesn't mention this option any more, it may be deprecated or it may be kept for compatibility; I cannot test this (feedback or edit is welcome). split-windowtakes percentages that refer to the available space, i.e. to the old size of the pane that is about to shrink to make space for the new pane (at least this is how it works in my oldish tmux with-p). This is why numbers like22appear ( 20/(20+70) ≈ 22 ). According to the documentationresize-paneuses percentages of the window size.- I use or don't use
-dto stay in the current pane or make the new one current, depending on which pane I need to target with the nextsplit-window. - When I need to specify/select a pane that fits a token like
{top-right}, I use the token. - I do not use
send-keysto run commands. In general do not usesend-keysto run commands. Any(?) tmux command that creates a new shell inside tmux can run a shell command instead. In the example scriptecho "step 0"; bashis such shell command. It includesbashat the end, so the pane doesn't exit when the actual command (echo) finishes. An alternative is theremain-on-exitoption. Your shell commands (watch) can work indefinitely, so you may not need such tricks. Running a shell command withsend-keyslike you do in your script makes sense if the command affects the shell it runs in and your goal is to work interactively in the shell prepared this way. E.g. the command may set variables or source a script; or you want to be able to interruptwatchand have it in the shell history. In any other case the "right" way is to pass commands withsplit-window,respawn-paneor some similar tmux command.
Additional note:
cat /proc/cpuinfo | grep "MHz" | …is a useless use ofcat. Better ways:</proc/cpuinfo grep "MHz" | … grep "MHz" /proc/cpuinfo | …