<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Diego Bruning</title>
    <description>The latest articles on DEV Community by Diego Bruning (@diego_bruning).</description>
    <link>https://dev.to/diego_bruning</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F399279%2Fd3b744b6-78ed-4cec-a0ed-34ffe766cb4b.jpeg</url>
      <title>DEV Community: Diego Bruning</title>
      <link>https://dev.to/diego_bruning</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/diego_bruning"/>
    <language>en</language>
    <item>
      <title>Making your terminal more productive with Tmux</title>
      <dc:creator>Diego Bruning</dc:creator>
      <pubDate>Sun, 31 May 2020 23:42:19 +0000</pubDate>
      <link>https://dev.to/diego_bruning/making-your-terminal-more-productive-with-tmux-2497</link>
      <guid>https://dev.to/diego_bruning/making-your-terminal-more-productive-with-tmux-2497</guid>
      <description>&lt;p&gt;Tmux is a terminal multiplexer. This means that you can start a Tmux session and open multiple windows within that session. Each window occupies the entire screen and can be divided into rectangular panels.&lt;/p&gt;

&lt;p&gt;With Tmux we can easily switch between different programs in one terminal, disconnect them and connect them again to a different terminal.&lt;/p&gt;

&lt;p&gt;Programs running on Tmux will continue to run even if we are disconnected, as Tmux sessions are persistent.&lt;/p&gt;

&lt;p&gt;All commands in Tmux start with a prefix, which by default is&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;ctrl + b&lt;/code&gt;&lt;br&gt;
&lt;br&gt;
.&lt;/p&gt;
&lt;h3&gt;
  
  
  Installing Tmux:
&lt;/h3&gt;

&lt;p&gt;We can install Tmux in two ways: through the package manager of the operating system or through the official repository.&lt;/p&gt;
&lt;h4&gt;
  
  
  Installing Tmux from the official repository:
&lt;/h4&gt;

&lt;p&gt;First check the latest version in the official repository and then change the version in the commands that follow (in my case the most recent version was 3.1b):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# downloading
$ wget https://github.com/tmux/tmux/releases/download/3.1b/tmux-3.1b.tar.gz
# unzipping 
$ tar -zxvf tmux-3.1b.tar.gz
# accessing the folder
$ cd  tmux-3.1b/
# Setting 
$ ./configure  &amp;amp;&amp;amp; make 
# Installing 
$ sudo make install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When executing the command "./configure &amp;amp;&amp;amp; make" on a machine with ubuntu I had the following errors that you may have:&lt;/p&gt;

&lt;p&gt;configure: error: no acceptable C compiler found in $PATH&lt;br&gt;
lconfigure: error: "ibevent-dev"&lt;br&gt;
configure: error: "ncurses-dev"&lt;br&gt;
para cada um uma solução:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ apt-get install build-essential
$ apt-get install libevent-dev
$ apt-get install ncurses-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Installing Tmux via the package manager:
&lt;/h4&gt;

&lt;p&gt;Ubuntu and Debian&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ sudo apt install tmux&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;CentOS and Fedora&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ sudo yum install tmux&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;macOS&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ brew install tmux&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Session:
&lt;/h3&gt;

&lt;p&gt;Now with the installation complete, just run the tmux command on the terminal, if everything went well you will see a green bar at the bottom of the terminal.&lt;/p&gt;

&lt;p&gt;When running tmux a session is created and the programs running in this session will continue to run even if the terminal window is closed.&lt;/p&gt;

&lt;p&gt;In this green bar we have some information:&lt;br&gt;
In the right corner, from right to left we have the current date, the time, and the name of the current computer.&lt;br&gt;
In the left corner between brackets we have the current session, then we have the window (in case 0) and the name of the software that is running (in the case bash). The '*' indicates which window is currently active.&lt;/p&gt;

&lt;p&gt;Tmux has a "base" shortcut for executing the commands which is ctrl b, we will call this shortcut prefix, so whenever we quote the prefix key we will be talking about this combination.&lt;/p&gt;

&lt;p&gt;To list the sessions use the command:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ tmux ls&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;| 0: 1 windows (created Tue May 26 13:11:04 2020) (attached)&lt;br&gt;
0 is the name of the session, 1 windows means you have a window open in the session.&lt;br&gt;
With the session started we can use some shortcuts to execute commands in Tmx. For a list of all Tmux commands, type:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;ctrl+b ?&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Creating named Tmux sessions&lt;br&gt;
By default, sessions in tmux are named numerically. Sometimes it can be useful to create a named session. We can do this with the command:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ tmux new -s session_name&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;Disconnecting from a session&lt;br&gt;
You can disconnect from the Tmux session and return to your normal shell by typing:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ Ctrl+b d&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;If we run a program before disconnecting, it will continue to run even after we disconnect.&lt;/p&gt;

&lt;p&gt;Reconnecting to a Tmux session:&lt;br&gt;
First we need the name of the session, we can get this with the command "tmux ls". With the session name, just execute the command (replacing sessao_nome):&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ tmux attach-session -t sessao_nome&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Windows
&lt;/h3&gt;

&lt;p&gt;With tmux we can create windows from within the same session. To create a new window we use:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;$ Ctrl+b c&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;We can see that in the green bar two windows will appear and one of them will be marked with the ‘*’ that indicates the current window.&lt;br&gt;
To switch to the previous window we can change the command:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Ctrl+b p&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;para mudarmos para o próxima janela:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Crtl+b n&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;and to change to a specific window just use the prefix and the window number:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Ctrl+b 0&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;We can rename a chord window with its own criteria, for that we use prefix +, :&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Ctrl+b ,&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;if we want to close a window we can use the prefix + &amp;amp;:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Crtl+b &amp;amp;&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Panels
&lt;/h3&gt;

&lt;p&gt;We can still divide the windows.&lt;br&gt;
Tmux allows you to divide vertically with the prefix + %:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Ctrl+b %&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;And horizontally with prefix + “:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Ctrl+b “&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;To navigate between the panels we use prefixes and arrows.&lt;/p&gt;

&lt;p&gt;We can convert a window panel with a + prefix!:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Ctrl+b !&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;To kill a panel we use the prefix + x:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Crtl+b x&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;We can also zoom in on a panel with the prefix + z, and then with the same command return to shared view:&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;code&gt;Crtl+b z&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Customizing Tmux
&lt;/h3&gt;

&lt;p&gt;When Tmux is started, it reads its configuration parameters in ~/.tmux.conf.&lt;/p&gt;

&lt;p&gt;We are not going to detail this configuration, you can get more details on the project wiki. But we can for example change the color of the bar with adding the following configuration in the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# Customize the status line
set -g status-fg  green
set -g status-bg  black
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Conclusion
&lt;/h3&gt;

&lt;p&gt;This article was a quick introduction, there's a lot more on the project wiki and in the user manual, feel free to check it out, but you can start using it as we saw.&lt;/p&gt;

&lt;p&gt;Try it and then comment here if you felt any advantage in using it.&lt;/p&gt;

&lt;p&gt;Att.: &lt;a href="https://diegobruning.dibr3.com/" rel="noopener noreferrer"&gt;Diego Bruning&lt;/a&gt; &lt;/p&gt;

</description>
      <category>linux</category>
      <category>opensource</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
