20

Suppose I start tmux and immediately execute Ctrl+b+% and Ctrl+b+".

This gives me a tall pane on the left side of the screen; the right side of the screen has a top and bottom pane.

How can I configure tmux to start in this configuration without having to type these commands?

  • If your requirement is to open a few terminals all at once in a single click you can do it with terminator. Install it from software center. – SAGAR Nair Sep 27 '16 at 20:17
  • Thanks, that's a good command to know! For my particular case, this is for an ssh session to a remote computer. – Mark Harrison Sep 27 '16 at 20:20
17

Another option is to create an alias or another shell file in /bin for:

tmux new-session \; split-window -h \; split-window -v \; attach

or

tmux source-file ~/.tmux.conf

where ~/.tmux.conf

new
neww
splitw -h
splitw -v

For reference, same question has other options in SE, How to set up tmux so that it starts up with specified windows opened?

14
+100

You can use following shell script for your configuration:

#!/bin/sh 
tmux new-session -s "mySession" -d
tmux split-window -h
tmux split-window -v
tmux -2 attach-session -d 

This will give the required configuration of the screen with following commands as you mentioned. tmux --> Ctrl+b+% --> Ctrl+b+"

For reference please use tmux man page.

4

It can be easy to enable and disable automatic tmux sessions on login by using Byobu application. You can use Byobu as an interface to tmux to address this need, it makes it simple to do what you are asking. In a terminal, run following commands:

sudo apt-get install byobu
sudo byobu-enable
sudo -i

When the root user logs in via the console, SSH, or with sudo -i, Byobu will attach to an existing tmux session or create a new one if one is not already running. Use sudo -i instead of sudo -s. The -s option only starts a shell, not a login shell. You should use sudo -i to emulate a full login, which also loads roots ~/.profile, and this is where byobu will install itself when you run

byobu-enable.

You can configure different sessions from your .tmux.conf as below:

# initialize sessions
bind S source-file ~/.tmux/session1 
bind s source-file ~/.tmux/session2

And then you can format the sessions as you require:

#session1
new  -s SessionName -n WindowName Command
neww -n foo/bar foo
splitw -v -p 50 -t 0 bar
selectw -t 1 
selectp -t 0

This would open 2 windows, the second of which would be named foo/bar and would be split vertically in half (50%) with foo running above bar. Focus would be in window 2 (foo/bar), top pane (foo).

Byobu makes setting up and starting tmux automatically very simple.

  • 1
    why bind S vs bind s? (first large S, then small s?) – knb Sep 13 '17 at 7:40
2

The tmux-resurrect plugin will enable setting up session persistence as well as provide additional functionality for saving and restoring settings across tmux sessions.

Many additional features are available. From the plugin web page:

"This plugin goes to great lengths to save and restore all the details from your tmux environment. Here's what's been taken care of:

  • all sessions, windows, panes and their order
  • current working directory for each pane
  • exact pane layouts within windows (even when zoomed)
  • active and alternative session
  • active and alternative window for each session
  • windows with focus active pane for each window
  • "grouped sessions" (useful feature when using tmux with multiple monitors) programs running within a pane! "

Installation:

  1. In the terminal, navigate to your tmux plugin directory(in my case, ~/dotfiles/tmux/plugins).
  2. Clone the repository with the command: git clone https://github.com/tmux-plugins/tmux-resurrect.

  3. Edit your .tmux.conf file and add the line set -g @plugin 'tmux-plugins/tmux-resurrect'.

  4. Reload the tmux environment with the command: tmux source-file ~/dotfiles/tmux/tmux.conf.
  5. Enter the layout that you want. In this case Ctrl-b % and Ctrl-b ".
  6. Save your tmux session by entering the command Ctrl-b + Ctrl-s.
  7. When you next start your tmux session, enter the command Ctrl-b + Ctrl-r to restore your tmux session.

As mentioned previously, in addition to setting up the pane layout of the tmux session, this plugin can also set up persistent working directories as well as have your running applications restart with each session.

1

I wrote myself a little bash script:

# filename tmuxv in /home/<username>/Bash/tmuxv/

#!/bin/bash
tmux new-session \; split-window -v \; rename-window ${1} \; attach

and put an alias in my ~/.bash_aliases

alias tmuxv="/home/<username>/Bash/tmuxv/tmuxv"

So now I can simply type tmuxv PYTHON and I have a vertically split tmux session with a window named PYTHON, which is nice because the window name gets reflected in my gnome-terminals tab name.

  • 1
    Good answer, but please remove the question at the end. Try asking it as a new question, which will make sure more people see it. – Tom Brossman Oct 30 '18 at 11:57

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.