Tmux

From OpenSimulator

Jump to: navigation, search


Tmux is a terminal multiplexer: it enables a number of terminals (or windows), each running a separate program, to be created, accessed, and controlled from a single screen. tmux may be detached from a screen and continue running in the background, then later reattached.

A lot of people are using GNU Screen to run OpenSimulator but Tmux is offering some good tools to enhance the task.

Tmux is mostly working like Screen except that the default shortcut to run commands is ctrl+b instead of ctrl+a.

A quick crash course is available here.

Contents

Installation

Debian

sudo aptitude install tmux

If you would like to use ctrl+a instead of ctrl+b and get some usefull shortcuts, you can use a ~/.tmux.conf file and add inside

# remap prefix to Control + a
set -g prefix C-a
unbind C-b
bind C-a send-prefix
# force a reload of the config file
unbind r
bind r source-file ~/.tmux.conf
# quick pane cycling
unbind ^A
bind ^A select-pane -t :.+

Running sessions

You can start sessions using the syntax :

tmux new -s my_session_name

to detach the session, you can use the shortcut ctrl+b d

Then, you can use the "-t" (target) switch to target a session for a command.

tmux attach -t my_session_name

Windows and panes

Windows

Tmux has the ability to use "tabs" for the display. Tabs are called "windows". You can create a "window" using the shortcut ctrl+b c Then switch between windows with ctrl+b [0-9]

Panes

Tmux has the ability to split a window in several "panes". To split vertically, use the shortcut ctrl+b " To split horizontally, use the shortcut ctrl+b % To move the cursor between panes, use the shortcut ctrl+b and arrows keys If you use the 3 keys at the same time, you can resize the actual pane.

Sharing sessions

Here is the intersting part to use Tmux with OpenSimulator. The session is shared using a "socket" and the users sharing the session have to be allowed to write in this socket.

Prepare the place

We will create a group and add all the users sharing the session in this group. We will create a folder in the /tmp folder to host the socket. We will give the write authorization to the group on the socket folder.

groupadd tmux-share
addgroup tmux-share myuser
addgroup tmux-share myotheruser
mkdir /tmp/tmux-share
chgrp tmux-share /tmp/tmux-share
chmod -R 2775 /tmp/tmux-share

Create the session

tmux -S /tmp/tmux-share/1 new-session -s mysession

Join the session

tmux -S /tmp/tmux-share/1 attach -t mysession

Send commands to the session

This can be usefull to send commands to the sessions using a batch script or anything else. To do it, you can use a syntax like this :

tmux send-keys -t mysession:1 "ls" C-m

so if you would like to send commands using the socket :

tmux -S /tmp/tmux-share/1 send-keys -t mysession:1 "ls" C-m

log the output

To prevent you losing too much time looking for the answer, here is a working (at least) version of a command to log the output.

tmux -S /tmp/tmux-share/test new -s test1
tmux -S /tmp/tmux-share/test pipe-pane -o -t test1 'cat >> tmux.log'
Personal tools
General
About This Wiki