Sick Gaming
Fedora - 4 tips for better tmux sessions - Printable Version

+- Sick Gaming (https://www.sickgaming.net)
+-- Forum: Computers (https://www.sickgaming.net/forum-86.html)
+--- Forum: Linux, FreeBSD, and Unix types (https://www.sickgaming.net/forum-88.html)
+--- Thread: Fedora - 4 tips for better tmux sessions (/thread-86209.html)



Fedora - 4 tips for better tmux sessions - xSicKxBot - 08-28-2018

4 tips for better tmux sessions

<div style="margin: 5px 5% 10px 5%;"><img src="http://www.sickgaming.net/blog/wp-content/uploads/2018/08/4-tips-for-better-tmux-sessions.png" width="1024" height="690" title="" alt="" /></div><div><p>The tmux utility, a terminal multiplexer, lets you treat your terminal as a multi-paned window into your system. You can arrange the configuration, run different processes in each, and generally make better use of your screen. We introduced some readers to this powerful tool <a href="https://fedoramagazine.org/use-tmux-more-powerful-terminal/">in this earlier article</a>. Here are some tips that will help you get more out of tmux if you’re getting started.</p>
<p><span id="more-22406"></span></p>
<p>This article assumes your current prefix key is <strong>Ctrl+b</strong>. If you’ve remapped that prefix, simply substitute your prefix in its place.</p>
<h2>Set your terminal to automatically use tmux</h2>
<p>One of the biggest benefits of tmux is being able to disconnect and reconnect to sesions at wilI. This makes remote login sessions more powerful. Have you ever lost a connection and wished you could get back the work you were doing on the remote system? With tmux this problem is solved.</p>
<p>However, you may sometimes find yourself doing work on a remote system, and realize you didn’t start a session. One way to avoid this is to have tmux start or attach every time you login to a system with in interactive shell.</p>
<p>Add this to your remote system’s <em>~/.bash_profile</em> file:</p>
<pre>if [ -z "$TMUX" ]; then tmux attach -t default || tmux new -s default fi</pre>
<p>Then logout of the remote system, and log back in with SSH. You’ll find you’re in a tmux session named <em>default.</em> This session will be regenerated at next login if you exit it. But more importantly, if you detach from it as normal, your work is waiting for you next time you login — especially useful if your connection is interrupted.</p>
<p>Of course you can add this to your local system as well. Note that terminals inside most GUIs won’t use the default session automatically, because they aren’t login shells. While you can change that behavior, it may result in nesting that makes the session less usable, so proceed with caution.</p>
<h2>Use zoom to focus on a single process</h2>
<p>While the point of tmux is to offer multiple windows, panes, and processes in a single session, sometimes you need to focus. If you’re in a process and need more space, or to focus on a single task, the zoom command works well. It expands the current pane to take up the entire current window space.</p>
<p>Zoom can be useful in other situations too. For instance, imagine you’re using a terminal window in a graphical desktop. Panes can make it harder to copy and paste multiple lines from inside your tmux session. If you zoom the pane, you can do a clean copy/paste of multiple lines of data with ease.</p>
<p>To zoom into the current pane, hit <strong>Ctrl+b, z</strong>. When you’re finished with the zoom function, hit the same key combo to unzoom the pane.</p>
<h2>Bind some useful commands</h2>
<p>By default tmux has numerous commands available. But it’s helpful to have some of the more common operations bound to keys you can easily remember. Here are some examples you can add to your <em>~/.tmux.conf</em> file to make sessions more enjoyable:</p>
<pre>bind r source-file ~/.tmux.conf \; display "Reloaded config"</pre>
<p>This command rereads the commands and bindings in your config file. Once you add this binding, exit any tmux sessions and then restart one. Now after you make any other future changes, simply run <strong>Ctrl+b, r</strong> and the changes will be part of your existing session.</p>
<pre>bind V split-window -h bind H split-window</pre>
<p>These commands make it easier to split the current window across a vertical axis (note that’s  <strong>Shift+V</strong>) or across a horizontal axis (<strong>Shift+H</strong>).</p>
<p>If you want to see how all keys are bound, use <strong>Ctrl+B, ?</strong> to see a list. You may see keys bound in <em>copy-mode</em> first, for when you’re working with copy and paste inside tmux. The <em>prefix</em> mode bindings are where you’ll see ones you’ve added above. Feel free to experiment with your own!</p>
<h2>Use powerline for great justice</h2>
<p><a href="https://fedoramagazine.org/add-power-terminal-powerline/">As reported in a previous Fedora Magazine article</a>, the <em>powerline</em> utility is a fantastic addition to your shell. But it also has capabilities when used with tmux. Because tmux takes over the entire terminal space, the powerline window can provide more than just a better shell prompt.</p>
<p><a href="https://fedoramagazine.org/wp-content/uploads/2018/08/Screenshot-from-2018-08-25-19-36-53.png"><img class="aligncenter size-large wp-image-22456" src="http://www.sickgaming.net/blog/wp-content/uploads/2018/08/4-tips-for-better-tmux-sessions.png" alt="Screenshot of tmux powerline in git folder" width="616" height="415" /></a></p>
<p>If you haven’t already, follow the instructions in the <a href="https://fedoramagazine.org/add-power-terminal-powerline/">Magazine’s powerline article</a> to install that utility. Then, install the addon <a href="https://fedoramagazine.org/howto-use-sudo/">using sudo</a>:</p>
<pre>sudo dnf install tmux-powerline</pre>
<p>Now restart your session, and you’ll see a spiffy new status line at the bottom. Depending on the terminal width, the default status line now shows your current session ID, open windows, system information, date and time, and hostname. If you change directory into a git-controlled project, you’ll see the branch and color-coded status as well.</p>
<p>Of course, this status bar is highly configurable as well. Enjoy your new supercharged tmux session, and have fun experimenting with it.</p>
<hr />
<p>Photo by <a href="https://unsplash.com/photos/S-Med_LVdio?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Pamela Saunders</a> on <a href="https://unsplash.com/search/photos/window?utm_source=unsplash&amp;utm_medium=referral&amp;utm_content=creditCopyText">Unsplash</a>.</p>
</div>