tmux 

Send to Kindle
home » snippets » tmux


Pages
manpage        



Specifying targets

target-session is either the name of a session (as listed by the list-sessions command) or the name of a client with the same syntax as target-client, in which case the session attached to the client is used. When looking for the session name, tmux initially searches for an exact match; if none is found, the session names are checked for any for which target-session is a prefix or for which it matches as an fnmatch(3) pattern. If a single match is found, it is used as the target session; multiple matches produce an error. If a session is omit- ted, the current session is used if available; if no current session is available, the most recently used is chosen.

target-window specifies a window in the form session:window. session follows the same rules as for target-session, and window is looked for in order: as a window index, for example mysession:1; as an exact window name, such as mysession:mywindow; then as an fnmatch(3) pattern or the start of a window name, such as mysession:mywin* or mysession:mywin. An empty window name specifies the next unused index if appropriate (for example the new-window and link-window commands) otherwise the current window in session is chosen. The special character "!" uses the last (previously current) window, or "+" and "-" are the next window or the previous window by number. When the argument does not contain a colon, tmux first attempts to parse it as window; if that fails, an attempt is made to match a session.

target-pane takes a similar form to target-window but with the optional addition of a period followed by a pane index, for example: mysession:mywindow.1. If the pane index is omitted, the currently active pane in the specified window is used. If neither a colon nor period appears, tmux first attempts to use the argument as a pane index; if that fails, it is looked up as for target-window. A "+" or a "-" indicate the next or previous pane index, respectively. One of the strings top, bottom, left, right, top-left, top-right, bottom-left or bottom-right may be used instead of a pane index. E.g. mysession:mywindow.top-left

The special characters "+" and "-" may be followed by an offset, for example:

  select-window -t:+2

When dealing with a session that doesn't contain sequential window indexes, they will be correctly skipped.

tmux also gives each pane created in a server an identifier consisting of a % and a number, starting from zero. A pane's identifier is unique for the life of the tmux server and is passed to the child process of the pane in the TMUX_PANE environment variable. It may be used alone to target a pane or the window containing it.

Setup

# Do the building, etc. from /tmp
cd /tmp

# Download the source
curl -L -O 'http://downloads.sourceforge.net/tmux/tmux-1.6.tar.gz'
# Unpack and build
tar zxf tmux-1.6.tar.gz

# cd into the unpacked folder
cd tmux-1.6

# configure and build dance
./configure
make
sudo make install

Configure it

Save the attached .tmux.conf file into your home folder.

# Verify that our config file exists.
ls -l ~/.tmux.conf

# It doesn't need to be readable by anyone except you so
# you can chmod it to set that permission.  Here, we
# give group read permission so your coworkers can read
# it if they like.
chmod 640 ~/.tmux.config

Creating a new session / Attaching to an existing session.

# Create and attach to a new session called "main"
tmux -2 new -s main
# Use "tmux -2 attach -t main" if you had already
# created this session and were attaching to it now.

# To detach from that session, press the keys `d
# The backtick - ` - is the "escape"/control key to tell
# tmux to do things.
#
# To get help, type `?
#
# To create a new tab, use `c
#
# To switch to a different tab, either use `<Left> and
# `<Right> to go left and right, or `N to go directly to
# the tag numbered N.  If N > 9, then use `g followed
# by the number and ENTER.
#
# Scrolling works differently.
# `[ to start scroll mode.
# When in scroll mode, use CTRL-B to scroll up and
# CTRL-F to scroll down (those are the same keys that
# vim uses.) and finally press ENTER to exit scroll
# mode.

Once you're created and attached to a session, you can kill the ssh connection anytime without care.

Whenever you ssh in again, use tmux -2 attach -t main to get back to where you were with all the tabs as they were.

HowTo

Reload ~/.tmux.conf without killing your session

tmux bind-key R source-file $HOME/.tmux.conf

Escaping characters in #(command) syntax

From the FAQ

When using the #(command) construction to include the output from a command in the status line, the command will be parsed twice. First, when it's read by the configuration file or the command-prompt parser, and second when the status line is being drawn and the command is passed to the shell. For example, to echo the string "(test)" to the status line, either single or double quotes could be used:

set -g status-right "#(echo \\\\(test\\\\))"
set -g status-right '#(echo \\\(test\\\))'

In both cases, the status-right option will be set to the string "#(echo \\(test\\))" and the command executed will be "echo \(test\)".

vim displays reverse video instead of italics, while less displays italics (or just regular text) instead of reverse. What's wrong?

From the FAQ

Screen's terminfo description lacks italics mode and has standout mode in its place, but using the same escape sequence that urxvt uses for italics. This means applications (like vim) looking for italics will not find it and might turn to reverse in its place, while applications (like less) asking for standout will end up with italics instead of reverse. To make applications aware that tmux supports italics and to use a proper escape sequence for standout, you'll need to create a new terminfo file with modified sgr, smso, rmso, sitm and ritm entries:

$ mkdir $HOME/.terminfo/
$ screen_terminfo="screen"
$ infocmp "$screen_terminfo" | sed \
  -e 's/^screen[^|]*|[^,]*,/screen-it|screen with italics support,/' \
  -e 's/%?%p1%t;3%/%?%p1%t;7%/' \
  -e 's/smso=[^,]*,/smso=\\E[7m,/' \
  -e 's/rmso=[^,]*,/rmso=\\E[27m,/' \
  -e '$s/$/ sitm=\\E[3m, ritm=\\E[23m,/' > /tmp/screen.terminfo
$ tic /tmp/screen.terminfo

And tell tmux to use it in ~/.tmux.conf:

set -g default-terminal "screen-it"

If your terminal supports 256 colors, use:

$ screen_terminfo="screen-256color"

instead of "screen". See the FAQ entry about 256 colors support for more info. Also note that tmux will still display reverse video on terminals that do not support italics.