{
  "version": "https://jsonfeed.org/version/1",
  "title": "Dracula on enumerator.dev",
  "icon": "<no value>",
  "home_page_url": "https://enumerator.dev/",
  "feed_url": "https://enumerator.dev/feed.json",
  "items": [
      {
        "id": "https://enumerator.dev/creating-a-tmux-colour-theme/",
        "title": "Creating a tmux Colour Theme",
        "content_html": "<p>I recently decided to use the <a href=\"https://draculatheme.com/\">Dracula</a> in my coding environment. Love it or hate it, I&rsquo;ve been working with Vim and <a href=\"https://github.com/tmux/tmux\">tmux</a> 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.</p>\n<p>When I switched Vim over to Dracula, I immediately realized that I needed to change my tmux colours too!</p>\n<p>Here&rsquo;s how I approached writing a theme in my tmux config. But first, this is what it looks like! 😍</p>\n<p><a href=\"/images/posts/tmux-theme/tmux-dracula.png\"><img src=\"/images/posts/tmux-theme/tmux-dracula.png\" alt=\"a screenshot of a terminal with a tmux window\"></a></p>\n<h2 id=\"general-setup\">General Setup</h2>\n<p>First, I wanted all the hex codes for Dracula colours right in front of me so I didn&rsquo;t have to keep switching to a browser window. Then, lets tell tmux to use a terminal that supports colours.</p>\n<p>You&rsquo;ll notice that I&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.</p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-fallback\" data-lang=\"fallback\"><span class=\"line\"><span class=\"cl\"># Dracula Colours\n</span></span><span class=\"line\"><span class=\"cl\"># background_color &#39;#282a36&#39;\n</span></span><span class=\"line\"><span class=\"cl\"># current_line_color &#39;#44475a&#39;\n</span></span><span class=\"line\"><span class=\"cl\"># foreground_color &#39;#f8f8f2&#39;\n</span></span><span class=\"line\"><span class=\"cl\"># comment_color &#39;#6272a4&#39;\n</span></span><span class=\"line\"><span class=\"cl\"># cyan &#39;#8be9fd&#39;\n</span></span><span class=\"line\"><span class=\"cl\"># green &#39;#50fa7b&#39;\n</span></span><span class=\"line\"><span class=\"cl\"># orange &#39;#ffb86c&#39;\n</span></span><span class=\"line\"><span class=\"cl\"># pink &#39;#ff79c6&#39;\n</span></span><span class=\"line\"><span class=\"cl\"># purple &#39;#bd93f9&#39;\n</span></span><span class=\"line\"><span class=\"cl\"># red &#39;#ff5555&#39;\n</span></span><span class=\"line\"><span class=\"cl\"># yellow &#39;#f1fa8c&#39;\n</span></span><span class=\"line\"><span class=\"cl\">\n</span></span><span class=\"line\"><span class=\"cl\">set -g default-terminal &#34;screen-256color&#34;\n</span></span></code></pre></div><h2 id=\"borders\">Borders</h2>\n<p>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&rsquo;re familiar with iTerm, think of panes like a horizontal or vertical split.</p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-fallback\" data-lang=\"fallback\"><span class=\"line\"><span class=\"cl\"># pane border\n</span></span><span class=\"line\"><span class=\"cl\">set -g pane-border-style fg=&#39;#6272a4&#39;\n</span></span><span class=\"line\"><span class=\"cl\">set -g pane-active-border-style fg=&#39;#ff79c6&#39;\n</span></span></code></pre></div><p>Here we&rsquo;ve set two styles. The default border colour is Dracula&rsquo;s dark purple comment colour. tumx style directives are a comma-separated list of styles for foreground, <code>fg</code>, and background <code>bg</code>.</p>\n<p><code>fg</code> and <code>bg</code> each accept a colour and a list of attributes. The tmux docs gives a list of all the attributes you can use:</p>\n<blockquote>\n<p>The attributes is either none or a comma-delimited list of one or more of: <code>bright</code> (or <code>bold</code>), <code>dim</code>, <code>underscore</code>, <code>blink</code>, <code>reverse</code>, <code>hidden</code>, <code>italics</code>, or <code>strikethrough</code> to turn an attribute on, or an attribute prefixed with <code>no</code> to turn one off.</p>\n</blockquote>\n<p>These two styles tell tmux to make all the boarders dark purple, but if my cursor is in a window, make that pane&rsquo;s borders pink.</p>\n<h2 id=\"message-style\">Message Style</h2>\n<p>At the bottom of a tmux window, you&rsquo;ll see the status bar. But this gets covered up by the tmux command line and any messages from tmux.</p>\n<p>I kept this similar to the status bar, with a grey background and blue text.</p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-fallback\" data-lang=\"fallback\"><span class=\"line\"><span class=\"cl\"># message text\n</span></span><span class=\"line\"><span class=\"cl\">set -g message-style bg=&#39;#44475a&#39;,fg=&#39;#8be9fd&#39;\n</span></span></code></pre></div><h2 id=\"status-line\">Status Line</h2>\n<p>The status line is comprised of three parts. <code>status-left</code>, <code>window-status</code> and <code>status-right</code>. Remember how I said that tmux has multiple windows. You can think of these like tabs in iTerm. All of the <code>window-status</code> directives style these tabs.</p>\n<p>Lets start with some basic configs.</p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-fallback\" data-lang=\"fallback\"><span class=\"line\"><span class=\"cl\">set -g status-style bg=&#39;#44475a&#39;,fg=&#39;#bd93f9&#39;\n</span></span><span class=\"line\"><span class=\"cl\">set -g status-interval 1\n</span></span></code></pre></div><p>Here we set the background to a dark grey and the foreground to purple. Although, the purple will get overwritten later.</p>\n<p>The next line is important for what we&rsquo;re going to do with <code>status-right</code> later. It tells tmux to refresh the status line every second.</p>\n<p>All right, now for <code>status-left</code>.</p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-fallback\" data-lang=\"fallback\"><span class=\"line\"><span class=\"cl\"># status left\n</span></span><span class=\"line\"><span class=\"cl\"># are we controlling tmux or the content of the panes?\n</span></span><span class=\"line\"><span class=\"cl\">set -g status-left &#39;#[bg=#f8f8f2]#[fg=#282a36]#{?client_prefix,#[bg=#ff79c6],} ☺ &#39;\n</span></span></code></pre></div><p>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.</p>\n<p>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&rsquo;t do anything. And finally The string ends with <code>☺</code>.</p>\n<p>This gives me a quick way to see if I&rsquo;ve typed the prefix or not. Handy when you&rsquo;re prone to mistyping, or when you get distracted in the middle of switching panes or windows.</p>\n<p>Next, I want to add to this status-left string. Passing the <code>a</code> option into <code>set</code> tells tmux to append this string to the previous one rather than overwrite it.</p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-fallback\" data-lang=\"fallback\"><span class=\"line\"><span class=\"cl\"># are we zoomed into a pane?\n</span></span><span class=\"line\"><span class=\"cl\">set -ga status-left &#39;#[bg=#44475a]#[fg=#ff79c6] #{?window_zoomed_flag, ↕  ,   }&#39;\n</span></span></code></pre></div><p>Looks similar to the one above, right. This time, I&rsquo;m displaying an arrow if I&rsquo;ve zoomed one of my panes to take up the whole window. Otherwise, I&rsquo;m leaving this blank.</p>\n<p>Okay! On to to <code>window-status</code>.</p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-fallback\" data-lang=\"fallback\"><span class=\"line\"><span class=\"cl\"># window status\n</span></span><span class=\"line\"><span class=\"cl\">set-window-option -g window-status-style fg=&#39;#bd93f9&#39;,bg=default\n</span></span><span class=\"line\"><span class=\"cl\">set-window-option -g window-status-current-style fg=&#39;#ff79c6&#39;,bg=&#39;#282a36&#39;\n</span></span></code></pre></div><p>Here I&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. <code>window-status-format</code> is where things get more interesting.</p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-fallback\" data-lang=\"fallback\"><span class=\"line\"><span class=\"cl\">set -g window-status-current-format &#34;#[fg=#44475a]#[bg=#bd93f9]#[fg=#f8f8f2]#[bg=#bd93f9] #I #W #[fg=#bd93f9]#[bg=#44475a]&#34;\n</span></span><span class=\"line\"><span class=\"cl\">set -g window-status-format &#34;#[fg=#f8f8f2]#[bg=#44475a]#I #W #[fg=#44475a] &#34;\n</span></span></code></pre></div><p>This looks similar to what we have above, but there&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 <code></code>. Then to display the name of the window I&rsquo;m using <code>#I</code>, which is a short-hand for the <code>window_index</code> variable and <code>#W</code>, which is short for <code>window_name</code></p>\n<p>Almost done! <code>status-right</code> should look pretty familiar now.</p>\n<div class=\"highlight\"><pre tabindex=\"0\" class=\"chroma\"><code class=\"language-gdscript3\" data-lang=\"gdscript3\"><span class=\"line\"><span class=\"cl\"><span class=\"c1\"># status right</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"n\">set</span> <span class=\"o\">-</span><span class=\"n\">g</span> <span class=\"n\">status</span><span class=\"o\">-</span><span class=\"n\">right</span> <span class=\"s1\">&#39;#[fg=#8be9fd,bg=#44475a]#[fg=#44475a,bg=#8be9fd] #(tmux-mem-cpu-load -g 5 --interval 2) &#39;</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"n\">set</span> <span class=\"o\">-</span><span class=\"n\">ga</span> <span class=\"n\">status</span><span class=\"o\">-</span><span class=\"n\">right</span> <span class=\"s1\">&#39;#[fg=#ff79c6,bg=#8be9fd]#[fg=#44475a,bg=#ff79c6] #(uptime | cut -f 4-5 -d &#34; &#34; | cut -f 1 -d &#34;,&#34;) &#39;</span>\n</span></span><span class=\"line\"><span class=\"cl\"><span class=\"n\">set</span> <span class=\"o\">-</span><span class=\"n\">ga</span> <span class=\"n\">status</span><span class=\"o\">-</span><span class=\"n\">right</span> <span class=\"s1\">&#39;#[fg=#bd93f9,bg=#ff79c6]#[fg=#f8f8f2,bg=#bd93f9] %a %H:%M:%S #[fg=#6272a4]%Y-%m-</span><span class=\"si\">%d</span><span class=\"s1\"> &#39;</span>\n</span></span></code></pre></div><p>The difference here is that I&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&rsquo;s been since the last reboot.</p>\n<h2 id=\"conclusion\">Conclusion</h2>\n<p>Yay, a Dracula theme!!! I&rsquo;m still working on perfecting my tmux config. Lots of it is borrowed from other people&rsquo;s dot files, but I&rsquo;m pretty happy with my Dracula theme. Now I have to do the same form my command prompt!</p>\n",
        "date_published": "2019-08-03T12:00:00+00:00",
        "url": "https://enumerator.dev/creating-a-tmux-colour-theme/",
        "tags": ["dotfiles","dracula","tmux"]
      }
  ]
}
