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?
Another option is to create an alias or another shell file in
/bin
for:or
where
~/.tmux.conf
For reference, same question has other options in SE, How to set up tmux so that it starts up with specified windows opened?
You can use following shell script for your configuration:
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.
It can be easy to enable and disable automatic
tmux
sessions on login by using Byobu application. You can use Byobu as an interface totmux
to address this need, it makes it simple to do what you are asking. In a terminal, run following commands:When the root user logs in via the console, SSH, or with
sudo -i
, Byobu will attach to an existingtmux
session or create a new one if one is not already running. Usesudo -i
instead ofsudo -s
. The-s
option only starts a shell, not a login shell. You should usesudo -i
to emulate a full login, which also loadsroots ~/.profile
, and this is where byobu will install itself when you runbyobu-enable
.You can configure different sessions from your
.tmux.conf
as below:And then you can format the sessions as you require:
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.
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 with this plugin. From the plugin's project page:
Installation:
~/dotfiles/tmux/plugins
).Clone the repository with the command:
git clone https://github.com/tmux-plugins/tmux-resurrect
.Edit your
.tmux.conf
file and add the lineset -g @plugin 'tmux-plugins/tmux-resurrect'
.tmux source-file ~/dotfiles/tmux/tmux.conf
.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.
Here is a .bash_aliases function that opens up a tall pane on the left and splits the right pane vertically (see picture below).
"-t $SESSION:1.2" indicates you want to execute the command in the "work" session, in the first window, in the second pane (<prefix + q> lists pane numbers).
"G" is the vim command that takes you to the end of the file.
I wrote myself a little bash script:
and put an alias in my ~/.bash_aliases
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.