Background and Problem:
I have created a tmux script to open a few windows. It works great but then I wanted to place a vertically split pane on one window and resize it to 5 characters tall. I cannot get my bash script to resize the pane properly. Depending on the commands I try, it will increase or decrease the size but it acts like it's bound to some range when executing from bash.
Some Commands/Variations I've tried:
tmux split-window -v -l 5 -t 0with and without the
tmux split-window -v -p 5 -t 0with and without the
tmux split-window -vfollowed by
tmux resize-pane -D 23 -t 1with and without the -t parameter
- I also tried variations of:
tmux send-keys C-b '"' C-mfollowed by
tmux send-keys C-b ':resize-pane -D 20'but that typically dumps the quote and the resize-pane command into the actual terminal buffer instead of executing the command using tmux.
Best case scenario from any number of those is the pane resizes from half of the screen (56 lines / 2 = 28 lines) to 20 lines tall (my terminal is 56 lines high and thus half – 20 = 8). Or, if I set the resize-pane command to -U for up and then set some high number, it will make the pane much taller but still will only go so large, keeping pane 0 a certain height. I just can't seem to create a pane and resize it to 5 – 10 lines tall from a bash script. I can run all of the listed commands from within tmux using C-b and : (my default prefix key) and they work exactly as expected.
My tmux bash script:
# the name of your primary tmux session SESSION=$USER # if the session is already running, just attach to it. tmux has-session -t $SESSION if [ $? -eq 0 ]; then echo "Session $SESSION already exists. Attaching..." sleep 1 tmux -2 attach -t $SESSION exit 0; fi # create a new session, named $SESSION, and detach from it tmux -2 new-session -d -s $SESSION # Now populate the session with the windows you use every day # 0 - VIM tmux new-window -t $SESSION:0 -k -n VIM tmux send-keys -t $SESSION:0 'cd /home/aDir/myDir/' C-m tmux send-keys -t $SESSION:0 'vim .' C-m tmux split-window -v -l 5 -t 0 <--- HERE IS WHERE I WAS SWAPPING/TRYING COMMANDS # 1 - MySQL tmux new-window -t $SESSION:1 -k -n MySQL 'mysql -u root -p******** mydb' # 2 - Shell tmux new-window -t $SESSION:2 -k -n Shell 'sudo -s' tmux select-window -t $SESSION:0 tmux -2 attach -t $SESSION
Additionally, I tried removing everything but the initial create new window and tried splitting and resizing with no other commands being sent (i.e. adding the additional windows and opening a directory in VIM).
As an aside, on execution of this script, I get a terminal message saying "failed to connect to server: Connection refused" message but all of my windows are working and operating as expected (MySQL and VIM open perfectly and my sudo commands waits for my password). Not sure what server is trying to be connected to (MySQL is local) and failing but seemingly not affecting any functionality I seek.