captainarkdotnet/output/my-tmux-configuration.html

406 lines
18 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>My tmux configuration</title>
<link href="https://captainark.net/rss.xml" type="application/atom+xml" rel="alternate" title="Sysadmining. All day. Every day. Full Atom Feed" />
<!-- Bootstrap Core CSS -->
<link href="https://captainark.net/theme/css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="https://captainark.net/theme/css/clean-blog.min.css" rel="stylesheet">
<!-- Code highlight color scheme -->
<link href="https://captainark.net/theme/css/code_blocks/github.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Lora:400,700,400italic,700italic' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'>
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
<meta name="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...">
<meta name="author" content="Antoine Joubert">
<meta property="og:locale" content="">
<meta property="og:site_name" content="Sysadmining. All day. Every day.">
<meta property="og:type" content="article">
<meta property="article:author" content="https://captainark.net/author/antoine-joubert.html">
<meta property="og:url" content="https://captainark.net/my-tmux-configuration.html">
<meta property="og:title" content="My tmux configuration">
<meta property="article:published_time" content="2016-02-02 00:00:00+01:00">
<meta property="og: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...">
<meta property="og:image" content="https://captainark.net//bg.png">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="@captainark">
<meta name="twitter:title" content="My tmux configuration">
<meta name="twitter:image" content="https://captainark.net//bg.png">
<meta name="twitter: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...">
</head>
<body>
<!-- Navigation -->
<nav class="navbar navbar-default navbar-custom navbar-fixed-top">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header page-scroll">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="https://captainark.net/">Sysadmining. All day. Every day.</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav navbar-right">
<li><a href="/">Homepage</a></li>
<li><a href="/rss.xml">RSS</a></li>
<li><a href="/categories.html">Categories</a></li>
<li><a href="https://captainark.net/pages/about.html">About</a></li>
<li><a href="https://captainark.net/pages/resume.html">Resume</a></li>
</ul>
</div>
<!-- /.navbar-collapse -->
</div>
<!-- /.container -->
</nav>
<!-- Page Header -->
<header class="intro-header" style="background-image: url('/bg.png')">
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<div class="post-heading">
<h1>My tmux configuration</h1>
<span class="meta">Posted by
<a href="https://captainark.net/author/antoine-joubert.html">Antoine Joubert</a>
on Tue 02 February 2016
</span>
</div>
</div>
</div>
</div>
</header>
<!-- Main Content -->
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<!-- Post Content -->
<article>
<p><a href="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><a href="images/tmux_fullsize.png"><img alt="tmux" src="images/tmux.png"></a></p>
<p>This screenshot was done on Mac OS X, using the Terminal app and this <a href="https://github.com/tomislav/osx-terminal.app-colors-solarized">Solarized theme</a>.</p>
<p>I figured I'd share my tmux configuration here !</p>
<h2>Installing tmux</h2>
<p>tmux is available on Debian. I suggest using the <a href="https://packages.debian.org/jessie-backports/tmux">jessie backports</a> version :</p>
<p><code>apt -t jessie-backports install tmux</code></p>
<p>tmux is also available on Mac OS X using <a href="http://brew.sh/">brew</a> :</p>
<p><code>brew install tmux</code></p>
<h2>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>
<div class="highlight"><pre><span></span># 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 &quot;screen-256color&quot;
set -g aggressive-resize off
set-window-option -g xterm-keys on
#set-window-option -g mode-mouse off
# command history
set -g history-limit 10000
# messages
set -g message-bg default
set -g message-fg red
# no visual activity
set -g visual-activity off
set -g visual-bell off
# status bar
set-option -g status-justify centre
set-option -g status-bg default
set-option -g status-fg blue
set-option -g status-interval 5
set-option -g status-left-length 30
set-option -g status-left &#39;#[fg=red][ #[fg=white]#H #[fg=red]]#[default]&#39;
set-option -g status-right &#39;#[fg=red][ #[fg=white]%R %d/%m #[fg=red]]#[default]&#39;
# modes
set-option -g mode-bg default
set-option -g mode-fg blue
# inactive window format
set-window-option -g window-status-format &#39;#I:#W#F&#39;
set-window-option -g monitor-activity on
#set-window-option -g monitor-content on # not available in tmux 2.0
# activity in a window
set-window-option -g window-status-activity-attr dim
set-window-option -g window-status-activity-bg default
set-window-option -g window-status-activity-fg yellow
# content in a window # not available in tmux 2.0
#set-window-option -g window-status-content-attr dim
#set-window-option -g window-status-content-bg default
#set-window-option -g window-status-content-fg red
# active window format
set-window-option -g window-status-current-fg white
set-window-option -g window-status-current-bg default
set-window-option -g window-status-current-format &#39;#[fg=red](#[default]#I:#W#F#[fg=red])#[default]&#39;
# reload tmux configuration
unbind r
bind r source-file ~/.tmux.conf \; display &quot;Configuration reloaded!&quot;
# 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 &quot;rename-window %%&quot;
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 &quot;kill-window&quot;
unbind l
bind l refresh-client
unbind &#39;&quot;&#39;
bind &#39;&quot;&#39; choose-window
</pre></div>
<h2>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>
<div class="highlight"><pre><span></span>mytmux<span class="o">()</span> <span class="o">{</span>
tmux has-session -t mytmux
<span class="k">if</span> <span class="o">[</span> <span class="nv">$?</span> !<span class="o">=</span> <span class="m">0</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
tmux new-session -s mytmux -n <span class="k">$(</span>hostname<span class="k">)</span> -d
tmux new-window -t mytmux:1 -n <span class="k">$(</span>hostname<span class="k">)</span>
tmux new-window -t mytmux:2 -n <span class="k">$(</span>hostname<span class="k">)</span>
tmux new-window -t mytmux:3 -n <span class="k">$(</span>hostname<span class="k">)</span>
tmux new-window -t mytmux:4 -n <span class="k">$(</span>hostname<span class="k">)</span>
tmux new-window -t mytmux:5 -n <span class="k">$(</span>hostname<span class="k">)</span>
tmux new-window -t mytmux:6 -n <span class="k">$(</span>hostname<span class="k">)</span>
tmux new-window -t mytmux:7 -n <span class="k">$(</span>hostname<span class="k">)</span>
tmux new-window -t mytmux:8 -n <span class="k">$(</span>hostname<span class="k">)</span>
tmux new-window -t mytmux:9 -n <span class="k">$(</span>hostname<span class="k">)</span>
tmux <span class="k">select</span>-window -t mytmux:0
<span class="k">fi</span>
tmux attach -t mytmux
<span class="o">}</span>
</pre></div>
<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>
<div class="highlight"><pre><span></span><span class="k">if</span> <span class="o">[</span> -n <span class="s2">&quot;</span><span class="nv">$TMUX</span><span class="s2">&quot;</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
ssh<span class="o">()</span> <span class="o">{</span>
<span class="k">if</span> <span class="o">[</span> <span class="nv">$#</span> -le <span class="m">2</span> <span class="o">]</span><span class="p">;</span> <span class="k">then</span>
tmux rename-window <span class="s2">&quot;</span><span class="si">${</span><span class="p">@: -1</span><span class="si">}</span><span class="s2">&quot;</span>
<span class="nb">command</span> ssh <span class="s2">&quot;</span><span class="nv">$@</span><span class="s2">&quot;</span>
tmux rename-window <span class="s2">&quot;</span><span class="k">$(</span>hostname<span class="k">)</span><span class="s2">&quot;</span>
<span class="k">else</span>
<span class="nb">command</span> ssh <span class="s2">&quot;</span><span class="nv">$@</span><span class="s2">&quot;</span>
<span class="k">fi</span>
<span class="o">}</span>
<span class="k">fi</span>
</pre></div>
<h2>Conclusion</h2>
<p>That's all ! As always, please do leave a comment if you've found something useful in this article !</p>
</article>
<hr>
<div class="comments">
<h2>Comments !</h2>
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = 'captainark';
var disqus_identifier = 'my-tmux-configuration.html';
var disqus_url = 'https://captainark.net/my-tmux-configuration.html';
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = '//captainark.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script>
<noscript>Please enable JavaScript to view the comments.</noscript>
</div>
</div>
</div>
</div>
<hr>
<!-- Footer -->
<footer>
<div class="container">
<div class="row">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
<ul class="list-inline text-center">
<li>
<a href="mailto:contact@captainark.net">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-envelope fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="https://twitter.com/captainark">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-twitter fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="https://github.com/captainark">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-github fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="http://www.last.fm/user/captainark">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-lastfm fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="https://steamcommunity.com/id/captainark">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-steam fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
<li>
<a href="http://www.twitch.tv/captainark">
<span class="fa-stack fa-lg">
<i class="fa fa-circle fa-stack-2x"></i>
<i class="fa fa-twitch fa-stack-1x fa-inverse"></i>
</span>
</a>
</li>
</ul>
<p class="copyright text-muted">
Blog powered by <a href="http://getpelican.com">Pelican</a>,
which takes great advantage of <a href="http://python.org">Python</a>. <br /> &copy; Antoine Joubert
</p> </div>
</div>
</div>
</footer>
<!-- jQuery -->
<script src="https://captainark.net/theme/js/jquery.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="https://captainark.net/theme/js/bootstrap.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="https://captainark.net/theme/js/clean-blog.min.js"></script>
<script type="text/javascript">
var pkBaseURL = "www.captainark.net/stats";
var _paq = _paq || [];
_paq.push(["trackPageView"]);
_paq.push(["enableLinkTracking"]);
(function() {
var u=(("https:" == document.location.protocol) ? "https" : "http")+"://"+pkBaseURL+"/";
_paq.push(["setTrackerUrl", u+"p.php7"]);
_paq.push(["setSiteId", "1"]);
var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript";
g.defer=true; g.async=true; g.src=u+"p.js"; s.parentNode.insertBefore(g,s);
})();
</script>
<script type="text/javascript">
var disqus_shortname = 'captainark';
(function () {
var s = document.createElement('script'); s.async = true;
s.type = 'text/javascript';
s.src = '//' + disqus_shortname + '.disqus.com/count.js';
(document.getElementsByTagName('HEAD')[0] || document.getElementsByTagName('BODY')[0]).appendChild(s);
}());
</script>
</body>
</html>