What are terminal multiplexers?
Terminal multiplexer is a tool allowing to have multiple sessions/windows in a single terminal display. It is useful to split screen into multiple shells or accessing to multiple windows from the current one. The most handy use is when you use remote computers/servers to do some computations (let say to learn a model on GPUs). Indeed, throw a ssh connection you can’t leave your session without killing your current process. While terminal multiplexers allow the user to log out and keeping the session active. It requires to simply detach the current session. After a reconnection throw ssh, you simply have to reattach your detached session (without loosing your processes).
I personally use it a lot on my local machine and on remote servers to have a homogeneous way to interact with my different setups. In this article I will expose Tmux software. In this post I will show you how to install/configure and use it.
I love to use only one multiplexer simultaneously but if you to use multiple ones with a specific profile for each of them I recommend you to look into tmuxp project. In this post, I will only explain how I configure Tmux and how I use it.
sudo apt install tmux
sudo dnf install tmux
All configurations are in ~/.tmux.conf file. In this section I will detail what is my personal config. My config files can be found here. I will update this section over time as my configuration evolve.
First, lets look at my configuration:
I do not modify a lot the tmux status bar, the only modifications are the following:
- the selected window appear in blue (the others are in green),
- the bottom right display the ram usage for the GPUs and the CPU RAM.
My configuration files are composed into two parts: bash scripts to acquire system informations and Tmux config file. To install my config you have to download the files here and do:
cp -r tmux_scripts ~/.tmux_scripts cp tmux.conf ~/.tmux.conf
My scripts are as follows:
gpu.shscript using nvidia-smi command (it is up to you to install it) to get GPU ram usage in Gio. It takes the GPU id as a parameter (first GPU being 0). It is up to you to add more calls to this script (in the tmux.conf file where I set status-right option) to add other GPUs. If you want to improve this behavior, feel free to contribute.
ram.shscript to get RAM usage in Gio.
The config file enable mouse interactions (for scrolling, select my split or resize my splits) It also modifies some colors and informations displayed in the status bar. The status bar is updated Look at The Tao of tmux book for more styling options and how to modify it.
First, let start a session. In your terminal (or terminal emulator) type this:
I currently use the default shortcuts combined with my mouse.
In this post I will only mention the ones I’m using.
To use tmux shortcuts, you have to press
<Ctrl+b> first then type:
"for a horizontal split.
%for a vertical split.
zto zoom in/out of the current terminal.
cto create a new tab in your multiplexer.
dto detach your session.
I do every other actions like selecting terminal tab, resizing split, select split, … using my mouse. To reattach your previous session, just type:
Bonus: Alternative for Gnome users
If you want a tmux-like well configured (by default) and you use Gnome with gnome-terminal, I recommend you to check out Byobu. It has a well explained video in its home page. Its shortcuts do not always work on other terminals (which is a no go for me as I use Konsole terminal emulator).
Hope it helps some of you.