I am new to using tmux in scripting and I am attempting to manipulate it so when I run a script I can have multiple screens attached and split in my Putty session, and also have it color coded and binded so that if I use ALT+arrow key it will switch to the next pane. This is what I have so far for coding:

tmux new-session -d -s PortalDB
tmux selectp -t PortalDB
tmux splitw -h -p 50
tmux attach -t PortalDB
tmux set-window-option -g window-status-current-bg yellow
tmux new-session -d -s HardwareAgent
tmux selectp -t HardwareAgent
tmux splitw -h -p 50
tmux attach -t HardwareAgent
tmux set-window-option -g window-status-current-bg blue
tmux new-session -d -s Profile
tmux selectp -t Profile
tmux splitw -h -p 50
tmux attach -t Profile
tmux set-window-option -g window-status-current-bg red
tmux new-session -d -s JoinCode
tmux selectp -t JoinCode
tmux splitw -h -p 50
tmux attach -t JoinCode
tmux set-window-option -g window-status-current-bg green

tmux bind -n M-Left select-pane -L
tmux bind -n M-Right select-pane -R
tmux bind -n M-Up select-pane -U
tmux bind -n M-Down select-pane -D

When I run the script, the color coding works, however I want it to split the screens horizontally, but instead I get this:


Can someone suggest a way where I can split the panes evenly? Another thing I noticed is that when I run this script, it runs 4 different windows attached to the sessions I named, I just need it to split horizontally 4 times in one window. Can anyone suggest how to make it as such?


2 Answers 2


I found a better way to code this without having so many tmuxs running and it does what I want through most part:

tmux new-window -a -n WinSplit
tmux new-session -d -s WinSplit
tmux selectp -t WinSplit
tmux split-window -v
tmux set-window-option -g window-status-current-bg blue
tmux split-window -v
tmux split-window -v
tmux select-layout even-vertical
tmux attach -t WinSplit

From man tmux:

split-window [-dhvP] [-l size | -p percentage] [-t target-pane]
                   (alias: splitw)
             Create a new pane by splitting target-pane: -h does a horizontal
             split and -v a vertical split; if neither is specified, -v is
             assumed.  The -l and -p options specify the size of the new pane
             in lines (for vertical split) or in cells (for horizontal split),
             or as a percentage, respectively.  All other options have the
             same meaning as for the new-window command.

So you should change all your splitw -h to split -v for vertical split.

  • Ok that worked. Is there any way to split the sessions so they all show on the same screen (as four seperate sessions just split horizontally)?
    – ryekayo
    Commented Jul 17, 2014 at 17:02
  • Also colors and binds are not working on the script..
    – ryekayo
    Commented Jul 17, 2014 at 17:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .