For example, if I run from window 0:

sleep 2;tmux split-window -h 

and switch to another window 1 with prefix-n before the sleep is over, the window split happens on the new window 1.

How to make the split always happen on window 0 when the command is run from window 0, regardless of the current window?

I have found this possibility:

win="$(tmux display-message -p '#I')";sleep 2;tmux split-window -h -t "$win"

based on: https://superuser.com/questions/385472/get-current-window-number-for-bash-prompt but I don't like it forces me to run an extra command before sleep 2 (which is a real useful command that takes a long time to finish in my use case), which is cumbersome.

Tested on tmux 2.5.




tmux automatically defines this variable for us, and it just works:

sleep 2;tmux split-window -h -t $TMUX_PANE

This gives focus to the split when it gets created, this can be prevented with -d:

sleep 2;tmux split-window -dh -t $TMUX_PANE

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.