Tmux

From Alpine Linux
Revision as of 14:27, 8 April 2023 by Quill (talk | contribs) (Added a troubleshooting section that included information on extra steps I had to take for mouse support in a TTY -Quillith)

tmux is a terminal multiplexer. It's a good tool for e.g. remote support. It can also be used to start a command you want to keep running after you close your console session (you can later on attach to your running session).

Install

In order to use tmux you will have to install it:

apk add tmux

Usage

Start a new session

To create a tmux session you just enter:

tmux

List existing sessions

When you have started some session(s) you can list them:

tmux ls

Tip: Above command can also be run as tmux list-sessions

You might get a list that looks like this:

0: 1 windows (created Wed Oct 24 15:12:12 2012) [126x35]
1: 1 windows (created Wed Oct 24 15:14:44 2012) [126x35]

Attach to a existing session

Lets say you want to attach to a existing session (e.g. the above 1: 1 windows session).

tmux attach -t 1

Tip: If you only have one session you don't need to specify session. Just run tmux attach

Controlling a session

While inside a tmux session, you can control it using keyboard shortcuts. We will only describe some of those alternatives.

Tip: To enter a keyboard shortcut that controls the current tmux session, you should click B while holding down CTRL
In the below examples this procedure is described as C-b

Get help

One of the most useful commands is the one that gives you 'help'.
While in your tmux session, click:

C-b ?

(Do not press/hold CTRL when clicking ?)

Detach from a session

Sometimes it's useful to just detach from a session without killing it.

C-b d

Tip: Try starting ping 127.0.0.1 while inside a session and then detach from the session.
After some while re-connect to the session using tmux attach.
Note that the "seq" value indicates that ping had continued running while you where detached from the session.

Close or kill a session

To 'kill' a session:

C-b &

Confirm by clicking y when prompted.

You can also 'kill' your session by entering:

exit

Troubleshooting

If you are aiming to use tmux on your TTY and want to enable mouse service, you may need to take an extra step. First, ensure that your tmux config file has mouse support enabled by adding this to the ~/.tmux.conf file. Make this file if it does not already exist.

set -g mouse on

Refresh your tmux session to see if that step was enough.

tmux source-file ~/.tmux.conf

If your mouse does not appear, install the following package: gpm

Enable and start gpm's service

rc-update add gpm
rc-service gpm start

Other terminal multiplexers

A similar tool is screen which is documented here.