<rss version="2.0">
  <channel>
    <title>Tmux on enumerator.dev</title>
    <link>https://enumerator.dev/t/tmux/</link>
    <description></description>
    
    <language>en-CA</language>
    
    <lastBuildDate>Sat, 03 Aug 2019 12:00:00 +0000</lastBuildDate>
    
    <item>
      <title>Creating a tmux Colour Theme</title>
      <link>https://enumerator.dev/creating-a-tmux-colour-theme/</link>
      <pubDate>Sat, 03 Aug 2019 12:00:00 +0000</pubDate>
      <guid>https://enumerator.dev/creating-a-tmux-colour-theme/</guid>
      <description>&lt;p&gt;I recently decided to use the &lt;a href=&#34;https://draculatheme.com/&#34;&gt;Dracula&lt;/a&gt; in my coding environment. Love it or hate it, I&amp;rsquo;ve been working with Vim and &lt;a href=&#34;https://github.com/tmux/tmux&#34;&gt;tmux&lt;/a&gt; for the past two years, and I inherited my Vim and tmux configurations from someone else. I dove headfirst into this environment and got used to it pretty quickly, but I never spent much time configuring it.&lt;/p&gt;
&lt;p&gt;When I switched Vim over to Dracula, I immediately realized that I needed to change my tmux colours too!&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s how I approached writing a theme in my tmux config. But first, this is what it looks like! 😍&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://enumerator.dev/images/posts/tmux-theme/tmux-dracula.png&#34;&gt;&lt;img src=&#34;https://enumerator.dev/images/posts/tmux-theme/tmux-dracula.png&#34; alt=&#34;a screenshot of a terminal with a tmux window&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;general-setup&#34;&gt;General Setup&lt;/h2&gt;
&lt;p&gt;First, I wanted all the hex codes for Dracula colours right in front of me so I didn&amp;rsquo;t have to keep switching to a browser window. Then, lets tell tmux to use a terminal that supports colours.&lt;/p&gt;
&lt;p&gt;You&amp;rsquo;ll notice that I&amp;rsquo;m using the hex codes for these colours. tmux supports passing hex codes in to the configs, but it will convert the hex code to the closest 256color.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;# Dracula Colours
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;# background_color &amp;#39;#282a36&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;# current_line_color &amp;#39;#44475a&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;# foreground_color &amp;#39;#f8f8f2&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;# comment_color &amp;#39;#6272a4&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;# cyan &amp;#39;#8be9fd&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;# green &amp;#39;#50fa7b&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;# orange &amp;#39;#ffb86c&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;# pink &amp;#39;#ff79c6&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;# purple &amp;#39;#bd93f9&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;# red &amp;#39;#ff5555&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;# yellow &amp;#39;#f1fa8c&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;set -g default-terminal &amp;#34;screen-256color&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;borders&#34;&gt;Borders&lt;/h2&gt;
&lt;p&gt;a tmux session can have windows and windows have panes. Each pane is a separate terminal session and each window can have one or more terminal sessions. If you&amp;rsquo;re familiar with iTerm, think of panes like a horizontal or vertical split.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;# pane border
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;set -g pane-border-style fg=&amp;#39;#6272a4&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;set -g pane-active-border-style fg=&amp;#39;#ff79c6&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here we&amp;rsquo;ve set two styles. The default border colour is Dracula&amp;rsquo;s dark purple comment colour. tumx style directives are a comma-separated list of styles for foreground, &lt;code&gt;fg&lt;/code&gt;, and background &lt;code&gt;bg&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;fg&lt;/code&gt; and &lt;code&gt;bg&lt;/code&gt; each accept a colour and a list of attributes. The tmux docs gives a list of all the attributes you can use:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The attributes is either none or a comma-delimited list of one or more of: &lt;code&gt;bright&lt;/code&gt; (or &lt;code&gt;bold&lt;/code&gt;), &lt;code&gt;dim&lt;/code&gt;, &lt;code&gt;underscore&lt;/code&gt;, &lt;code&gt;blink&lt;/code&gt;, &lt;code&gt;reverse&lt;/code&gt;, &lt;code&gt;hidden&lt;/code&gt;, &lt;code&gt;italics&lt;/code&gt;, or &lt;code&gt;strikethrough&lt;/code&gt; to turn an attribute on, or an attribute prefixed with &lt;code&gt;no&lt;/code&gt; to turn one off.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;These two styles tell tmux to make all the boarders dark purple, but if my cursor is in a window, make that pane&amp;rsquo;s borders pink.&lt;/p&gt;
&lt;h2 id=&#34;message-style&#34;&gt;Message Style&lt;/h2&gt;
&lt;p&gt;At the bottom of a tmux window, you&amp;rsquo;ll see the status bar. But this gets covered up by the tmux command line and any messages from tmux.&lt;/p&gt;
&lt;p&gt;I kept this similar to the status bar, with a grey background and blue text.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;# message text
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;set -g message-style bg=&amp;#39;#44475a&amp;#39;,fg=&amp;#39;#8be9fd&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&#34;status-line&#34;&gt;Status Line&lt;/h2&gt;
&lt;p&gt;The status line is comprised of three parts. &lt;code&gt;status-left&lt;/code&gt;, &lt;code&gt;window-status&lt;/code&gt; and &lt;code&gt;status-right&lt;/code&gt;. Remember how I said that tmux has multiple windows. You can think of these like tabs in iTerm. All of the &lt;code&gt;window-status&lt;/code&gt; directives style these tabs.&lt;/p&gt;
&lt;p&gt;Lets start with some basic configs.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;set -g status-style bg=&amp;#39;#44475a&amp;#39;,fg=&amp;#39;#bd93f9&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;set -g status-interval 1
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here we set the background to a dark grey and the foreground to purple. Although, the purple will get overwritten later.&lt;/p&gt;
&lt;p&gt;The next line is important for what we&amp;rsquo;re going to do with &lt;code&gt;status-right&lt;/code&gt; later. It tells tmux to refresh the status line every second.&lt;/p&gt;
&lt;p&gt;All right, now for &lt;code&gt;status-left&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;# status left
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;# are we controlling tmux or the content of the panes?
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;set -g status-left &amp;#39;#[bg=#f8f8f2]#[fg=#282a36]#{?client_prefix,#[bg=#ff79c6],} ☺ &amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The syntax here is getting a little more tricky than when we were styling the status line. The status and window options take a single string as their argument, but you can pass styles in through square brackets and you can call tmux variables inside curly braces.&lt;/p&gt;
&lt;p&gt;So my status left line says, make the background light grey and the foreground dark grey. Then we have a conditional. Has the client prefix key been pressed? If so, lets actually make the background pink, if not, don&amp;rsquo;t do anything. And finally The string ends with &lt;code&gt;☺&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;This gives me a quick way to see if I&amp;rsquo;ve typed the prefix or not. Handy when you&amp;rsquo;re prone to mistyping, or when you get distracted in the middle of switching panes or windows.&lt;/p&gt;
&lt;p&gt;Next, I want to add to this status-left string. Passing the &lt;code&gt;a&lt;/code&gt; option into &lt;code&gt;set&lt;/code&gt; tells tmux to append this string to the previous one rather than overwrite it.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;# are we zoomed into a pane?
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;set -ga status-left &amp;#39;#[bg=#44475a]#[fg=#ff79c6] #{?window_zoomed_flag, ↕  ,   }&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Looks similar to the one above, right. This time, I&amp;rsquo;m displaying an arrow if I&amp;rsquo;ve zoomed one of my panes to take up the whole window. Otherwise, I&amp;rsquo;m leaving this blank.&lt;/p&gt;
&lt;p&gt;Okay! On to to &lt;code&gt;window-status&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;# window status
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;set-window-option -g window-status-style fg=&amp;#39;#bd93f9&amp;#39;,bg=default
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;set-window-option -g window-status-current-style fg=&amp;#39;#ff79c6&amp;#39;,bg=&amp;#39;#282a36&amp;#39;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Here I&amp;rsquo;ve set the default window status to blend in to the rest of the status bar and the active window to be purple with white text. &lt;code&gt;window-status-format&lt;/code&gt; is where things get more interesting.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-fallback&#34; data-lang=&#34;fallback&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;set -g window-status-current-format &amp;#34;#[fg=#44475a]#[bg=#bd93f9]#[fg=#f8f8f2]#[bg=#bd93f9] #I #W #[fg=#bd93f9]#[bg=#44475a]&amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;set -g window-status-format &amp;#34;#[fg=#f8f8f2]#[bg=#44475a]#I #W #[fg=#44475a] &amp;#34;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This looks similar to what we have above, but there&amp;rsquo;s some style tricks we need to do. I wanted to have triangular shapes delineating my windows similar to what Vim Powerline does. In order to get the style to work I have to toggle the foreground and background colours before and after the &lt;code&gt;&lt;/code&gt;. Then to display the name of the window I&amp;rsquo;m using &lt;code&gt;#I&lt;/code&gt;, which is a short-hand for the &lt;code&gt;window_index&lt;/code&gt; variable and &lt;code&gt;#W&lt;/code&gt;, which is short for &lt;code&gt;window_name&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Almost done! &lt;code&gt;status-right&lt;/code&gt; should look pretty familiar now.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-gdscript3&#34; data-lang=&#34;gdscript3&#34;&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;c1&#34;&gt;# status right&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;set&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;g&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;status&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;right&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;#[fg=#8be9fd,bg=#44475a]#[fg=#44475a,bg=#8be9fd] #(tmux-mem-cpu-load -g 5 --interval 2) &amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;set&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ga&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;status&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;right&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;#[fg=#ff79c6,bg=#8be9fd]#[fg=#44475a,bg=#ff79c6] #(uptime | cut -f 4-5 -d &amp;#34; &amp;#34; | cut -f 1 -d &amp;#34;,&amp;#34;) &amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class=&#34;line&#34;&gt;&lt;span class=&#34;cl&#34;&gt;&lt;span class=&#34;n&#34;&gt;set&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;ga&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;status&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;right&lt;/span&gt; &lt;span class=&#34;s1&#34;&gt;&amp;#39;#[fg=#bd93f9,bg=#ff79c6]#[fg=#f8f8f2,bg=#bd93f9] %a %H:%M:%S #[fg=#6272a4]%Y-%m-&lt;/span&gt;&lt;span class=&#34;si&#34;&gt;%d&lt;/span&gt;&lt;span class=&#34;s1&#34;&gt; &amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The difference here is that I&amp;rsquo;m using parentheses to tell tmux to execute a bash command. The first one displays a summary of my memory and CPU usage and the second one tells me how long it&amp;rsquo;s been since the last reboot.&lt;/p&gt;
&lt;h2 id=&#34;conclusion&#34;&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Yay, a Dracula theme!!! I&amp;rsquo;m still working on perfecting my tmux config. Lots of it is borrowed from other people&amp;rsquo;s dot files, but I&amp;rsquo;m pretty happy with my Dracula theme. Now I have to do the same form my command prompt!&lt;/p&gt;
</description>
    </item>
    
  </channel>
</rss>