<title>My tmux configuration · Sysadmining. All day. Every day.</title>
<metaname="description"content="tmux is a terminal mutiplexer. It lets you have multiples shells running in a single terminal emulator window and it keeps those shells running in the backgroun"/>
<p><ahref="https://tmux.github.io/">tmux</a> is a terminal mutiplexer. It lets you have multiples shells running in a single terminal emulator window and it keeps those shells running in the background should you need to close your terminal emulator.</p>
<p>I’ve played around with the configuration quite a bit to find settings that suit my needs. Here’s what it ended up looking like :</p>
<p>This screenshot was done on Mac OS X, using the Terminal app and this <ahref="https://github.com/tomislav/osx-terminal.app-colors-solarized">Solarized theme</a>.</p>
<p>I figured I’d share my tmux configuration here !</p>
<h2id="installing-tmux">Installing tmux</h2>
<p>tmux is available on Debian. I suggest using the <ahref="https://packages.debian.org/jessie-backports/tmux">jessie backports</a> version :</p>
<p>tmux is also available on Mac OS X using <ahref="http://brew.sh/">brew</a> :</p>
<p><code>brew install tmux</code></p>
<h2id="tmux-conf">tmux.conf</h2>
<p>I used screen before tmux, so I configured the prefix key on C-a instead of C-b. tmux has the advantage of being <em>much</em> simpler to configure than screen.</p>
<p>If you want to use this configuration, simply copy the following in ~/.tmux.conf. This file is read by default when tmux starts.</p>
<p>If you simply want to try it out, copy it in a file somewhere else and have tmux load with the -f parameter (<code>tmux -f ~/tmux-test.conf</code>).</p>
<pre><code># use utf8
set -g utf8
set-option -g status-utf8 on
set-window-option -g utf8 on
# do not wait on esc key
set-option -g escape-time 0
# completely disable automatic rename
set-window-option -g automatic-rename off
# basic settings
set -g default-terminal "screen-256color"
bind r source-file ~/.tmux.conf \; display "Configuration reloaded!"
# Screen-like keybinds
unbind C-b
set -g prefix ^A
set -g prefix2 ^Q
bind a send-prefix
bind q send-prefix
unbind c
bind c new-window
unbind ^C
bind ^C new-window
unbind n
bind n next-window
unbind ^N
bind ^N next-window
unbind A
bind A command-prompt "rename-window %%"
unbind p
bind p previous-window
unbind ^P
bind ^P previous-window
unbind a
bind a last-window
unbind ^A
bind ^A last-window
unbind [
bind Escape copy-mode
unbind w
bind w list-windows
unbind k
bind k confirm-before "kill-window"
unbind l
bind l refresh-client
unbind '"'
bind '"' choose-window
</code></pre>
<h2id="aliases">Aliases</h2>
<p>I also use two functions with tmux (in ~/.bash_aliases).</p>
<p>The first one creates a new “mytmux” tmux session if one doesn’t exist yet, opens 10 shells and selects the first one.</p>
<pre><codeclass="language-bash">mytmux() {
tmux has-session -t mytmux
if [ $? != 0 ]; then
tmux new-session -s mytmux -n $(hostname) -d
tmux new-window -t mytmux:1 -n $(hostname)
tmux new-window -t mytmux:2 -n $(hostname)
tmux new-window -t mytmux:3 -n $(hostname)
tmux new-window -t mytmux:4 -n $(hostname)
tmux new-window -t mytmux:5 -n $(hostname)
tmux new-window -t mytmux:6 -n $(hostname)
tmux new-window -t mytmux:7 -n $(hostname)
tmux new-window -t mytmux:8 -n $(hostname)
tmux new-window -t mytmux:9 -n $(hostname)
tmux select-window -t mytmux:0
fi
tmux attach -t mytmux
}
</code></pre>
<p>The second one changes the tmux window name whenever I ssh to a remote host, and switches the window name back to the name of my computer when I logout from the host.</p>
<pre><codeclass="language-bash">if [ -n "$TMUX" ]; then
ssh() {
if [ $# -le 2 ]; then
tmux rename-window "${@: -1}"
command ssh "$@"
tmux rename-window "$(hostname)"
else
command ssh "$@"
fi
}
fi
</code></pre>
<h2id="conclusion">Conclusion</h2>
<p>That’s all ! As always, please do leave a comment if you’ve found something useful in this article !</p>
<sectionclass="poweredby">Proudly generated by <aclass="icon-hugo"href="http://gohugo.io">HUGO</a>, with <aclass="icon-theme"href="https://github.com/vjeantet/hugo-theme-casper">Casper</a> theme</section>