<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">
    <channel>
        <title>Tim Visée</title>
        <link>https://timvisee.com</link>
        <description>Personal portfolio and blog of Tim Visée</description>
        <generator>Zola</generator>
        <language>en</language>
        <atom:link href="https://timvisee.com/categories/guide/rss.xml" rel="self" type="application/rss+xml"/>
        <lastBuildDate>Mon, 01 Mar 2021 00:00:00 +0000</lastBuildDate>
        
            <item>
                <title>List &amp; export your subreddits</title>
                <pubDate>Mon, 01 Mar 2021 00:00:00 +0000</pubDate>
                <link>https://timvisee.com/blog/list-export-your-subreddits/</link>
                <guid>https://timvisee.com/blog/list-export-your-subreddits/</guid>
                <description>&lt;p&gt;
    &lt;a href=&quot;&#x2F;blog&#x2F;list-export-your-subreddits&#x2F;header.png&quot; title=&quot;View full-size image&quot;&gt;
        
        
        
        &lt;img src=&quot;https:&amp;#x2F;&amp;#x2F;timvisee.com&amp;#x2F;processed_images&amp;#x2F;8acfba36cb7f2ef300.png&quot; &#x2F;&gt;
    &lt;&#x2F;a&gt;
&lt;&#x2F;p&gt;
&lt;p&gt;The last few years I&#x27;ve been wanting to export the list of subreddits I joined.
It&#x27;s fun to share with friends having a similar interest,
as I&#x27;ve collected many gems throughout the years.&lt;&#x2F;p&gt;
&lt;p&gt;To achieve this I&#x27;ve set-up a simple script.
It exports your subreddits to a plain text list.&lt;&#x2F;p&gt;
&lt;span id=&quot;continue-reading&quot;&gt;&lt;&#x2F;span&gt;&lt;h2 id=&quot;how-to-export&quot;&gt;How to export
    &lt;a class=&quot;anchor&quot; href=&quot;#how-to-export&quot; aria-label=&quot;Anchor link for: how-to-export&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h2&gt;
&lt;ol&gt;
&lt;li&gt;Visit &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;old.reddit.com&#x2F;subreddits&#x2F;mine&quot;&gt;old.reddit.com&#x2F;subreddits&#x2F;mine&lt;&#x2F;a&gt; in a desktop browser,
make sure you&#x27;re logged in.&lt;&#x2F;li&gt;
&lt;li&gt;On that page, &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Learn&#x2F;Common_questions&#x2F;What_are_browser_developer_tools#How_to_open_the_devtools_in_your_browser&quot;&gt;open&lt;&#x2F;a&gt; your browser developer tools (Keybind: &lt;em&gt;Ctrl+Shift+I&lt;&#x2F;em&gt;).&lt;&#x2F;li&gt;
&lt;li&gt;In the developer tools panel, open the &lt;strong&gt;Console&lt;&#x2F;strong&gt; tab.&lt;&#x2F;li&gt;
&lt;li&gt;Copy-and-paste the following snippet into the console, press &lt;em&gt;Enter&lt;&#x2F;em&gt; to run it:&lt;pre data-lang=&quot;javascript&quot; style=&quot;background-color:#191919;color:#f8f8f2;&quot; class=&quot;language-javascript &quot;&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span style=&quot;color:#8cdaff;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;body&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;).&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6699cc;&quot;&gt;replaceWith&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;&amp;lt;body&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8cdaff;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;.subscription-box&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;).&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6699cc;&quot;&gt;find&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;li&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;).&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6699cc;&quot;&gt;find&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;a.title&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;).&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8cdaff;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fc9354;&quot;&gt;_&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fc9354;&quot;&gt;d&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fbdfb5;&quot;&gt;=&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8cdaff;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;d&lt;&#x2F;span&gt;&lt;span&gt;).&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8cdaff;&quot;&gt;text&lt;&#x2F;span&gt;&lt;span&gt;()).&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6699cc;&quot;&gt;get&lt;&#x2F;span&gt;&lt;span&gt;().&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6699cc;&quot;&gt;join&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;&amp;lt;br&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;)&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;&amp;lt;&#x2F;body&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;);&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;javascript&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8cdaff;&quot;&gt;void&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;&#x2F;li&gt;
&lt;li&gt;Your full list of subreddits will appear on the webpage.&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;p&gt;&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;gist.github.com&#x2F;timvisee&#x2F;5af8d219d0a88740cdac2351f2f77247&quot;&gt;Here&lt;&#x2F;a&gt; is mine.&lt;&#x2F;p&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;Tap here if you&#x27;re a nerd.&lt;&#x2F;summary&gt;
&lt;h2 id=&quot;for-nerds&quot;&gt;For nerds
    &lt;a class=&quot;anchor&quot; href=&quot;#for-nerds&quot; aria-label=&quot;Anchor link for: for-nerds&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h2&gt;
&lt;p&gt;Here is the above snippet, expanded:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;javascript&quot; style=&quot;background-color:#191919;color:#f8f8f2;&quot; class=&quot;language-javascript &quot;&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span style=&quot;color:#6d6d6d;&quot;&gt;&#x2F;&#x2F; Pluck list of subreddits from page, build plain text list
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fbdfb5;&quot;&gt;var &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;subs &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8cdaff;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;.subscription-box&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6699cc;&quot;&gt;find&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;li&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6699cc;&quot;&gt;find&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;a.title&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;)
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8cdaff;&quot;&gt;map&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fc9354;&quot;&gt;_&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fc9354;&quot;&gt;d&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;) &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fbdfb5;&quot;&gt;=&amp;gt; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8cdaff;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;d&lt;&#x2F;span&gt;&lt;span&gt;).&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8cdaff;&quot;&gt;text&lt;&#x2F;span&gt;&lt;span&gt;())
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6699cc;&quot;&gt;get&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;span&gt;    .&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6699cc;&quot;&gt;join&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;&amp;lt;br&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6d6d6d;&quot;&gt;&#x2F;&#x2F; Put list of subreddits on page
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8cdaff;&quot;&gt;$&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;body&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;).&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6699cc;&quot;&gt;replaceWith&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;&amp;lt;body&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;+ &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;subs &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;+&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;&amp;lt;&#x2F;body&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;javascript&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8cdaff;&quot;&gt;void&lt;&#x2F;span&gt;&lt;span&gt;()
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Your complete list of subreddits is located in the sidebar on &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;old.reddit.com&#x2F;subreddits&#x2F;mine&quot;&gt;that&lt;&#x2F;a&gt; page.
The script plucks your list of reddits from this sidebar and puts it in an array.
Then the array is imploded in a string to show on the page.
Super simple.&lt;&#x2F;p&gt;
&lt;&#x2F;details&gt;
</description>
            </item>
        
            <item>
                <title>Reconnect to broken tmux session</title>
                <pubDate>Sun, 28 Feb 2021 00:00:00 +0000</pubDate>
                <link>https://timvisee.com/blog/reconnect-to-broken-tmux-session/</link>
                <guid>https://timvisee.com/blog/reconnect-to-broken-tmux-session/</guid>
                <description>&lt;p&gt;Ever tried to attach to a running tmux session, only to find that that fails?&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#191919;color:#f8f8f2;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;tmux&lt;&#x2F;span&gt;&lt;span&gt; attach
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6d6d6d;&quot;&gt;# no sessions
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;tmux&lt;&#x2F;span&gt;&lt;span&gt; ls
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6d6d6d;&quot;&gt;# error connecting to &#x2F;tmp&#x2F;tmux-1000&#x2F;default (No such file or directory)
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Even though you&#x27;re sure tmux is running fine, it shows up as running in your
task manager after all.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;em&gt;So, where are your precious tmux sessions?&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;span id=&quot;continue-reading&quot;&gt;&lt;&#x2F;span&gt;&lt;h2 id=&quot;socket-file&quot;&gt;Socket file
    &lt;a class=&quot;anchor&quot; href=&quot;#socket-file&quot; aria-label=&quot;Anchor link for: socket-file&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h2&gt;
&lt;p&gt;All your tmux sessions are hosted by a single tmux process. This is persistent
and keeps running until you quit all sessions again.&lt;&#x2F;p&gt;
&lt;p&gt;The process creates a socket file, other processes use this to talk to it. When
you invoke &lt;code&gt;tmux attach&lt;&#x2F;code&gt;, the program finds this socket and attaches to it
through the socket.&lt;&#x2F;p&gt;
&lt;p&gt;Now, what happens when you delete this file? Exactly, your &lt;code&gt;tmux&lt;&#x2F;code&gt; command doesn&#x27;t
know how to connect to the running server. That&#x27;s what we&#x27;re seeing here.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;recreate-socket&quot;&gt;Recreate socket
    &lt;a class=&quot;anchor&quot; href=&quot;#recreate-socket&quot; aria-label=&quot;Anchor link for: recreate-socket&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h2&gt;
&lt;p&gt;Because others had the same issue, tmux provides a feature to fix this. When you
send the &lt;code&gt;SIGUSR1&lt;&#x2F;code&gt; signal to the host process, it creates a fresh socket file
for you.&lt;&#x2F;p&gt;
&lt;p&gt;For this, you need to find the PID of the running tmux server. Find it through
your task manager, or invoke the following command to find the PID of the oldest
running tmux process:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#191919;color:#f8f8f2;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;pgrep&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fc9354;&quot;&gt; --oldest&lt;&#x2F;span&gt;&lt;span&gt; tmux
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6d6d6d;&quot;&gt;# 5612
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;For me it was &lt;code&gt;5612&lt;&#x2F;code&gt;, so I invoke the following and attach it again (be sure to
use your own PID):&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#191919;color:#f8f8f2;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;sudo&lt;&#x2F;span&gt;&lt;span&gt; kill&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fc9354;&quot;&gt; -SIGUSR1&lt;&#x2F;span&gt;&lt;span&gt; 5612
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;tmux&lt;&#x2F;span&gt;&lt;span&gt; attach
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Happy hacking!&lt;&#x2F;p&gt;
</description>
            </item>
        
            <item>
                <title>Dark mode toggle on your static website</title>
                <pubDate>Tue, 16 Jul 2019 00:00:00 +0000</pubDate>
                <link>https://timvisee.com/blog/dark-mode-toggle-on-static-website/</link>
                <guid>https://timvisee.com/blog/dark-mode-toggle-on-static-website/</guid>
                <description>&lt;p&gt;Developers &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;hashnode.com&#x2F;post&#x2F;which-color-theme-do-you-prefer-in-your-code-editor-ciq9e3wbn1avb0053p48nozw0&quot;&gt;like&lt;&#x2F;a&gt; dark themes. When looking at a screen
all day (or rather, night) long, a pale white background with black text is an
eyesore. Many software engineers prefer to use a dark theme with lower
contrast colors in their code editors, and many tools started shipping dark
visuals as default in the last few years.&lt;&#x2F;p&gt;
&lt;p&gt;
    &lt;a href=&quot;&#x2F;blog&#x2F;dark-mode-toggle-on-static-website&#x2F;screenshot.png&quot; title=&quot;View full-size image&quot;&gt;
        
        
        
        &lt;img src=&quot;https:&amp;#x2F;&amp;#x2F;timvisee.com&amp;#x2F;processed_images&amp;#x2F;9fe62b6e298b77aa00.png&quot; &#x2F;&gt;
    &lt;&#x2F;a&gt;
&lt;&#x2F;p&gt;
&lt;p&gt;I fall into that group as well and have been using these themes for so long
that I can&#x27;t even recall when I joined the dark side. I started to like these
dark themes a lot and find them more visually pleasing, appearing more...
&lt;em&gt;Professional&lt;&#x2F;em&gt;. To reflect this, I wanted to give my website – &lt;em&gt;this&lt;&#x2F;em&gt;
website – dark visuals as well.&lt;&#x2F;p&gt;
&lt;p&gt;This isn&#x27;t always a success. On some screens or in some light conditions the
dark theme can be difficult to read, and some just prefer a paper-like background
color anyway. I decided to create a dark&#x2F;light mode toggle to please everyone.&lt;&#x2F;p&gt;
&lt;p&gt;
  &lt;a href=&quot;#&quot; onclick=&quot;theme_toggle(); return false;&quot;&gt;
    &amp;#127763;
  &lt;&#x2F;a&gt;
  &lt;i&gt;&amp;mdash; Tap the moon icon, and see the magic happen.&lt;&#x2F;i&gt;
&lt;&#x2F;p&gt;
&lt;span id=&quot;continue-reading&quot;&gt;&lt;&#x2F;span&gt;&lt;h2 id=&quot;what-we-re-building&quot;&gt;What we&#x27;re building
    &lt;a class=&quot;anchor&quot; href=&quot;#what-we-re-building&quot; aria-label=&quot;Anchor link for: what-we-re-building&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h2&gt;
&lt;p&gt;Alright. In this post I&#x27;ll explain how to implement a light&#x2F;dark mode toggle
for your website, it&#x27;s super simple and adaptable. There are &lt;em&gt;a million&lt;&#x2F;em&gt;
tutorials for this on the Internet already, but here is my take on it in
some detail with a few tips.&lt;&#x2F;p&gt;
&lt;p&gt;This will use and support:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;toggle theme using a button with smooth transitions&lt;&#x2F;li&gt;
&lt;li&gt;remember chosen theme on a device, no flickering on page load&lt;&#x2F;li&gt;
&lt;li&gt;simple &amp;amp; effective to implement, works on static HTML pages&lt;&#x2F;li&gt;
&lt;li&gt;style sheet per color theme, keep it maintainable with SCSS variables&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;Continue to the next section for the implementation, or skip to &lt;a href=&quot;https:&#x2F;&#x2F;timvisee.com&#x2F;blog&#x2F;dark-mode-toggle-on-static-website&#x2F;#the-result&quot;&gt;The
result&lt;&#x2F;a&gt; just for the result.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;build-a-theme-toggle&quot;&gt;Build a theme toggle
    &lt;a class=&quot;anchor&quot; href=&quot;#build-a-theme-toggle&quot; aria-label=&quot;Anchor link for: build-a-theme-toggle&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h2&gt;
&lt;p&gt;&amp;quot;How is this be implemented?&amp;quot; I hear you ask. Well, it&#x27;s quite simple.&lt;&#x2F;p&gt;
&lt;p&gt;Because we&#x27;re working with a static HTML website, theme selection must be done on the
client. We&#x27;ll use two style sheets (each for a different color scheme), and some
simple JavaScript to toggle between these. The user preference will be
remembered across visits.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;load-two-style-sheets&quot;&gt;Load two style sheets
    &lt;a class=&quot;anchor&quot; href=&quot;#load-two-style-sheets&quot; aria-label=&quot;Anchor link for: load-two-style-sheets&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h3&gt;
&lt;p&gt;First off, &lt;strong&gt;load two style sheets&lt;&#x2F;strong&gt; inside the &lt;code&gt;&amp;lt;head&amp;gt;&lt;&#x2F;code&gt; block of your website
which &lt;strong&gt;replaces the existing&lt;&#x2F;strong&gt; style sheet you might have in your template.
Just link both to your existing sheet for now. Assign an &lt;code&gt;id&lt;&#x2F;code&gt; to easily
reference them from JavaScript, choose &lt;code&gt;style-light&lt;&#x2F;code&gt; and &lt;code&gt;style-dark&lt;&#x2F;code&gt;. The
latter of the two links gets the &lt;code&gt;disabled&lt;&#x2F;code&gt; attribute to disable it by default.
They won&#x27;t do anything yet, but this is to prepare for the toggle we&#x27;ll build
next.&lt;&#x2F;p&gt;
&lt;p&gt;I&#x27;m using &lt;code&gt;&#x2F;site.css&lt;&#x2F;code&gt;, which makes the imports &lt;strong&gt;look like this&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;html&quot; style=&quot;background-color:#191919;color:#f8f8f2;&quot; class=&quot;language-html &quot;&gt;&lt;code class=&quot;language-html&quot; data-lang=&quot;html&quot;&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;link &lt;&#x2F;span&gt;&lt;span style=&quot;color:#66a9ec;&quot;&gt;id&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;style-light&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#97d8ea;&quot;&gt;rel&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;stylesheet&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#97d8ea;&quot;&gt;href&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;&#x2F;site.css&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;&#x2F;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;link &lt;&#x2F;span&gt;&lt;span style=&quot;color:#66a9ec;&quot;&gt;id&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;style-dark&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#97d8ea;&quot;&gt;disabled rel&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;stylesheet&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#97d8ea;&quot;&gt;href&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;&#x2F;site.css&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;&#x2F;&amp;gt;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;add-a-toggle&quot;&gt;Add a toggle
    &lt;a class=&quot;anchor&quot; href=&quot;#add-a-toggle&quot; aria-label=&quot;Anchor link for: add-a-toggle&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h3&gt;
&lt;p&gt;Now we&#x27;ll create the toggle. After that, we can finalize and iteratively
experiment with a new color scheme.&lt;&#x2F;p&gt;
&lt;p&gt;&lt;strong&gt;Put an element&lt;&#x2F;strong&gt; that will &lt;strong&gt;act as toggle&lt;&#x2F;strong&gt; somewhere on your website where
it&#x27;s easily accessible. It should invoke the &lt;code&gt;theme_toggle()&lt;&#x2F;code&gt; function when
clicked which we&#x27;ll set up next. On my website it&#x27;s a contrast icon located
next to the page title, check it out. Though it can be anything, I recommend
to use an anchor, &lt;strong&gt;like this&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;html&quot; style=&quot;background-color:#191919;color:#f8f8f2;&quot; class=&quot;language-html &quot;&gt;&lt;code class=&quot;language-html&quot; data-lang=&quot;html&quot;&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;a &lt;&#x2F;span&gt;&lt;span style=&quot;color:#97d8ea;&quot;&gt;href&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;#&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#97d8ea;&quot;&gt;onclick&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;theme_toggle&lt;&#x2F;span&gt;&lt;span&gt;(); &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;return &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff8942;&quot;&gt;false&lt;&#x2F;span&gt;&lt;span&gt;;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#66a9ec;&quot;&gt;&amp;amp;#&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fdb082;&quot;&gt;127763;&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;a&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;toggle-with-javascript&quot;&gt;Toggle with JavaScript
    &lt;a class=&quot;anchor&quot; href=&quot;#toggle-with-javascript&quot; aria-label=&quot;Anchor link for: toggle-with-javascript&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h3&gt;
&lt;p&gt;Create a &lt;strong&gt;new JavaScript file&lt;&#x2F;strong&gt;, let&#x27;s call it &lt;code&gt;theme.js&lt;&#x2F;code&gt;. We need a function
&lt;code&gt;theme_set&lt;&#x2F;code&gt; to set the theme to light&#x2F;dark, and &lt;code&gt;theme_toggle&lt;&#x2F;code&gt; which toggles
the theme. This will toggle the &lt;code&gt;disabled&lt;&#x2F;code&gt; state for both style sheets
depending on a truthy parameter, and stores the preference as well in the
persistent &lt;code&gt;localStorage&lt;&#x2F;code&gt; JavaScript store on the client. The toggle function
queries the current state and sets the theme by negating it. It &lt;strong&gt;looks like
this&lt;&#x2F;strong&gt;:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; style=&quot;background-color:#191919;color:#f8f8f2;&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&lt;span style=&quot;font-style:italic;color:#fbdfb5;&quot;&gt;function &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8cdaff;&quot;&gt;theme_set&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fc9354;&quot;&gt;toggled&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;) &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    document.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6699cc;&quot;&gt;getElementById&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;style-light&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;).disabled &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;toggled&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    document.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6699cc;&quot;&gt;getElementById&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;style-dark&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;).disabled &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;= !&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;toggled&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;localStorage&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6699cc;&quot;&gt;setItem&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;theme-toggled&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;toggled &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;? &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fbdfb5;&quot;&gt;function &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8cdaff;&quot;&gt;theme_toggle&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;() &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8cdaff;&quot;&gt;theme_set&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;!&lt;&#x2F;span&gt;&lt;span&gt;document.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6699cc;&quot;&gt;getElementById&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;style-light&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;).disabled);
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;To restore the user preference we need to set the theme on page load, based on
the stored value. &lt;strong&gt;Append the following line&lt;&#x2F;strong&gt; for this:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; style=&quot;background-color:#191919;color:#f8f8f2;&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&lt;span style=&quot;color:#8cdaff;&quot;&gt;theme_set&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;localStorage&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6699cc;&quot;&gt;getItem&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;theme-toggled&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;));
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;To use this, &lt;strong&gt;load the script&lt;&#x2F;strong&gt; in the &lt;code&gt;&amp;lt;head&amp;gt;&lt;&#x2F;code&gt; block of your template
&lt;strong&gt;after&lt;&#x2F;strong&gt; the style sheets, like this:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; style=&quot;background-color:#191919;color:#f8f8f2;&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;script src&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;&#x2F;theme.js&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;type&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;text&#x2F;javascript&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;&amp;gt;&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&#x2F;script&amp;gt;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;h3 id=&quot;theme-style-sheets&quot;&gt;Theme style sheets
    &lt;a class=&quot;anchor&quot; href=&quot;#theme-style-sheets&quot; aria-label=&quot;Anchor link for: theme-style-sheets&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h3&gt;
&lt;p&gt;The toggle button is functional now, but you won&#x27;t see anything change yet.
We&#x27;ll look at creating a second style sheet with alternative colors now.&lt;&#x2F;p&gt;
&lt;p&gt;Generally speaking, the only thing that differs between these sheets will be
colors. I highly recommend using &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;sass-lang.com&#x2F;&quot;&gt;&lt;code&gt;SCSS&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; as a
&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Glossary&#x2F;CSS_preprocessor&quot;&gt;CSS preprocessor&lt;&#x2F;a&gt; for this to allow the usage of color
variables, for easy theme variant creation. This guide won&#x27;t cover
&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;sass-lang.com&#x2F;install&quot;&gt;installation&lt;&#x2F;a&gt; or &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;sass-lang.com&#x2F;guide&quot;&gt;usage&lt;&#x2F;a&gt; of &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;sass-lang.com&#x2F;&quot;&gt;SCSS&lt;&#x2F;a&gt;, though
some static site generators such as &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;getzola.org&#x2F;&quot;&gt;Zola&lt;&#x2F;a&gt; have built-in support for
this.  I&#x27;ll show how I&#x27;ve configured my colors for my template, but you can
skip this section and use two raw CSS files as well.&lt;&#x2F;p&gt;
&lt;p&gt;Create a &lt;code&gt;_colors_light.scss&lt;&#x2F;code&gt; and &lt;code&gt;_colors_dark.scss&lt;&#x2F;code&gt; file. (&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;gitlab.com&#x2F;timvisee&#x2F;timvisee.com&quot;&gt;This&lt;&#x2F;a&gt; site
uses &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;getzola.org&#x2F;&quot;&gt;Zola&lt;&#x2F;a&gt;, so I plase these in &lt;code&gt;&#x2F;sass&#x2F;&lt;&#x2F;code&gt; for automatic processing.)
Both should look similar to this, but having configured colors you choose for
your respective themes:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;css&quot; style=&quot;background-color:#191919;color:#f8f8f2;&quot; class=&quot;language-css &quot;&gt;&lt;code class=&quot;language-css&quot; data-lang=&quot;css&quot;&gt;&lt;span style=&quot;color:#6d6d6d;&quot;&gt;&#x2F;* File: _colors_light.scss *&#x2F;
&lt;&#x2F;span&gt;&lt;span&gt;$&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;color-text&lt;&#x2F;span&gt;&lt;span&gt;: #282828;
&lt;&#x2F;span&gt;&lt;span&gt;$&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;color-background&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#66a9ec;&quot;&gt;#fcfbf7&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;$&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;color-border&lt;&#x2F;span&gt;&lt;span&gt;: darken($&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;color-background&lt;&#x2F;span&gt;&lt;span&gt;, 50%);
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Moved all styles (used in any color variant) to &lt;code&gt;_site.scss&lt;&#x2F;code&gt;, and used the
color variables from above to adapt to the selected theme:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;css&quot; style=&quot;background-color:#191919;color:#f8f8f2;&quot; class=&quot;language-css &quot;&gt;&lt;code class=&quot;language-css&quot; data-lang=&quot;css&quot;&gt;&lt;span style=&quot;color:#6d6d6d;&quot;&gt;&#x2F;* File: _site.scss *&#x2F;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;body &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;color&lt;&#x2F;span&gt;&lt;span&gt;: $&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fdb082;&quot;&gt;color&lt;&#x2F;span&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fdb082;&quot;&gt;text&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;background-color&lt;&#x2F;span&gt;&lt;span&gt;: $&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fdb082;&quot;&gt;color&lt;&#x2F;span&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fdb082;&quot;&gt;background&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Then create a &lt;code&gt;site_light.scss&lt;&#x2F;code&gt; and &lt;code&gt;site_dark.scss&lt;&#x2F;code&gt; sheet as the base,
importing their respective color configuration and the shared site styles.&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;css&quot; style=&quot;background-color:#191919;color:#f8f8f2;&quot; class=&quot;language-css &quot;&gt;&lt;code class=&quot;language-css&quot; data-lang=&quot;css&quot;&gt;&lt;span style=&quot;color:#6d6d6d;&quot;&gt;&#x2F;* File: site_light.scss *&#x2F;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;@import &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;_colors_light&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;@import &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;_site&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;After processing these, you&#x27;ve created both a &lt;code&gt;site_light.css&lt;&#x2F;code&gt; and
&lt;code&gt;site_dark.css&lt;&#x2F;code&gt; sheet. And yeah, it was that simple to keep it maintainable.
Be sure to adapt the style sheet links in your template to the paths these new
sheets are located at.&lt;&#x2F;p&gt;
&lt;p&gt;Awesome! Your toggle should now work, and the preference should be remembered
across page reloads. Now take the time to tweak the color variants.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;smooth-transitions&quot;&gt;Smooth transitions
    &lt;a class=&quot;anchor&quot; href=&quot;#smooth-transitions&quot; aria-label=&quot;Anchor link for: smooth-transitions&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h3&gt;
&lt;p&gt;Once you&#x27;re settled with a second color scheme and everything works, you can
enable smooth transitioning between the two themes. We&#x27;ll use CSS
&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;CSS&#x2F;CSS_Transitions&#x2F;Using_CSS_transitions&quot;&gt;transitions&lt;&#x2F;a&gt; for this, which are awesome because they&#x27;re
simple and performant.&lt;&#x2F;p&gt;
&lt;p&gt;In your shared styles, you need to configure what CSS properties will smoothly
transition when changed. Imagine our &lt;code&gt;_site.scss&lt;&#x2F;code&gt; sheet from before, to
transition all properties that use variables we&#x27;ll modify it to add the
&lt;code&gt;transition&lt;&#x2F;code&gt; property like this:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;css&quot; style=&quot;background-color:#191919;color:#f8f8f2;&quot; class=&quot;language-css &quot;&gt;&lt;code class=&quot;language-css&quot; data-lang=&quot;css&quot;&gt;&lt;span style=&quot;color:#6d6d6d;&quot;&gt;&#x2F;* File: _site.scss *&#x2F;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;body &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;color&lt;&#x2F;span&gt;&lt;span&gt;: $&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fdb082;&quot;&gt;color&lt;&#x2F;span&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fdb082;&quot;&gt;text&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;background-color&lt;&#x2F;span&gt;&lt;span&gt;: $&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fdb082;&quot;&gt;color&lt;&#x2F;span&gt;&lt;span&gt;-&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fdb082;&quot;&gt;background&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;transition&lt;&#x2F;span&gt;&lt;span&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#fdb082;&quot;&gt;color 0.2&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;s &lt;&#x2F;span&gt;&lt;span style=&quot;color:#fdb082;&quot;&gt;ease-in-out&lt;&#x2F;span&gt;&lt;span&gt;,
&lt;&#x2F;span&gt;&lt;span&gt;      &lt;&#x2F;span&gt;&lt;span style=&quot;color:#fdb082;&quot;&gt;background-color 0.2&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;s &lt;&#x2F;span&gt;&lt;span style=&quot;color:#fdb082;&quot;&gt;ease-in-out&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;It will take some work to transition every dynamic property on your site, but
the result is great. Be sure to read the CSS transition documentation on
&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;developer.mozilla.org&#x2F;en-US&#x2F;docs&#x2F;Web&#x2F;CSS&#x2F;CSS_Transitions&#x2F;Using_CSS_transitions&quot;&gt;MDN&lt;&#x2F;a&gt;, because there&#x27;s a lot you can tweak and configure.&lt;&#x2F;p&gt;
&lt;p&gt;Hurray! That&#x27;s it, yes it was that simple. CSS is awesome for this as it
doesn&#x27;t require changes to the body of your website except for some imports.
Now you can publish your freshened website and profit.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;tips-tricks&quot;&gt;Tips &amp;amp; Tricks
    &lt;a class=&quot;anchor&quot; href=&quot;#tips-tricks&quot; aria-label=&quot;Anchor link for: tips-tricks&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h2&gt;
&lt;p&gt;You can modify the style sheet imports and script to use dark colors by default,
like on this website. Set the light scheme to be &lt;code&gt;disabled&lt;&#x2F;code&gt; by default, and
&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;gitlab.com&#x2F;timvisee&#x2F;timvisee.com&#x2F;blob&#x2F;7e533e64c5acb5eb3bcdbfc97e9d60f1aa0e0519&#x2F;themes&#x2F;zenn&#x2F;static&#x2F;js&#x2F;theme.js&quot;&gt;tweak&lt;&#x2F;a&gt; the script.&lt;&#x2F;p&gt;
&lt;p&gt;You might want to leave your existing style sheet as-is, and just use a second
sheet to override colors in the main sheet. Simply modify the script to only
toggle the &lt;code&gt;disabled&lt;&#x2F;code&gt; state for the overriding sheet, and query the overriding
sheet instead in the &lt;code&gt;theme_toggle&lt;&#x2F;code&gt; function.&lt;&#x2F;p&gt;
&lt;p&gt;This isn&#x27;t necessarily for light&#x2F;dark themes and works perfectly fine for
other color combinations as well.&lt;&#x2F;p&gt;
&lt;p&gt;If desired, you could implement even more themes with a more advanced theme
toggling script implementation.&lt;&#x2F;p&gt;
&lt;p&gt;For additional inspiration you can take a look at styles for &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;gitlab.com&#x2F;timvisee&#x2F;timvisee.com&#x2F;tree&#x2F;master&#x2F;themes&#x2F;zenn&#x2F;sass&quot;&gt;this&lt;&#x2F;a&gt;
website.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;the-result&quot;&gt;The result
    &lt;a class=&quot;anchor&quot; href=&quot;#the-result&quot; aria-label=&quot;Anchor link for: the-result&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h2&gt;
&lt;p&gt;To recap, here is an overview of what the changes should look like.&lt;&#x2F;p&gt;
&lt;p&gt;Your templates &lt;code&gt;&amp;lt;head&amp;gt;&lt;&#x2F;code&gt; should contain something like:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;html&quot; style=&quot;background-color:#191919;color:#f8f8f2;&quot; class=&quot;language-html &quot;&gt;&lt;code class=&quot;language-html&quot; data-lang=&quot;html&quot;&gt;&lt;span&gt;&amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;head&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#6d6d6d;&quot;&gt;&amp;lt;!-- snip ---&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;link &lt;&#x2F;span&gt;&lt;span style=&quot;color:#66a9ec;&quot;&gt;id&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;style-light&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#97d8ea;&quot;&gt;rel&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;stylesheet&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#97d8ea;&quot;&gt;href&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;&#x2F;site_light.css&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;&#x2F;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;link &lt;&#x2F;span&gt;&lt;span style=&quot;color:#66a9ec;&quot;&gt;id&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;style-dark&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#97d8ea;&quot;&gt;disabled rel&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;stylesheet&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#97d8ea;&quot;&gt;href&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;&#x2F;site_dark.css&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot; &lt;&#x2F;span&gt;&lt;span&gt;&#x2F;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span&gt;  &amp;lt;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;script &lt;&#x2F;span&gt;&lt;span style=&quot;color:#97d8ea;&quot;&gt;src&lt;&#x2F;span&gt;&lt;span&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;&#x2F;theme.js&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;quot;&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;script&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;  &lt;&#x2F;span&gt;&lt;span style=&quot;color:#6d6d6d;&quot;&gt;&amp;lt;!-- snip ---&amp;gt;
&lt;&#x2F;span&gt;&lt;span&gt;&amp;lt;&#x2F;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;head&lt;&#x2F;span&gt;&lt;span&gt;&amp;gt;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;And your &lt;code&gt;theme.js&lt;&#x2F;code&gt; file will look like:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;js&quot; style=&quot;background-color:#191919;color:#f8f8f2;&quot; class=&quot;language-js &quot;&gt;&lt;code class=&quot;language-js&quot; data-lang=&quot;js&quot;&gt;&lt;span style=&quot;color:#6d6d6d;&quot;&gt;&#x2F;&#x2F; File: theme.js
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6d6d6d;&quot;&gt;&#x2F;**
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6d6d6d;&quot;&gt; * Set and apply the normal or toggled theme.
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6d6d6d;&quot;&gt; *
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6d6d6d;&quot;&gt; * &lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fbdfb5;&quot;&gt;@param &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;toggled&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6d6d6d;&quot;&gt; Truthy value to show toggled, normal otherwise.
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6d6d6d;&quot;&gt; *&#x2F;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fbdfb5;&quot;&gt;function &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8cdaff;&quot;&gt;theme_set&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fc9354;&quot;&gt;toggled&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;) &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    document.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6699cc;&quot;&gt;getElementById&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;style-light&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;).disabled &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;= &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;toggled&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    document.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6699cc;&quot;&gt;getElementById&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;style-dark&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;).disabled &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;= !&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;toggled&lt;&#x2F;span&gt;&lt;span&gt;;
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;localStorage&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6699cc;&quot;&gt;setItem&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;theme-toggled&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;, &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;toggled &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;? &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;1&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39; &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;: &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;);
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6d6d6d;&quot;&gt;&#x2F;**
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6d6d6d;&quot;&gt; * Toggle the current theme.
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6d6d6d;&quot;&gt; *&#x2F;
&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fbdfb5;&quot;&gt;function &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8cdaff;&quot;&gt;theme_toggle&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;() &lt;&#x2F;span&gt;&lt;span&gt;{
&lt;&#x2F;span&gt;&lt;span&gt;    &lt;&#x2F;span&gt;&lt;span style=&quot;color:#8cdaff;&quot;&gt;theme_set&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;!&lt;&#x2F;span&gt;&lt;span&gt;document.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6699cc;&quot;&gt;getElementById&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;style-light&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;).disabled);
&lt;&#x2F;span&gt;&lt;span&gt;}
&lt;&#x2F;span&gt;&lt;span&gt;
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6d6d6d;&quot;&gt;&#x2F;&#x2F; Apply selected theme, stored in localStorage item
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#8cdaff;&quot;&gt;theme_set&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;localStorage&lt;&#x2F;span&gt;&lt;span&gt;.&lt;&#x2F;span&gt;&lt;span style=&quot;color:#6699cc;&quot;&gt;getItem&lt;&#x2F;span&gt;&lt;span&gt;(&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;theme-toggled&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span&gt;));
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Along with your custom &lt;code&gt;site_{light,dark}.css&lt;&#x2F;code&gt; sheets, this is all you need.&lt;&#x2F;p&gt;
&lt;p&gt;As always: &lt;em&gt;Hope this helps!&lt;&#x2F;em&gt; &lt;sub&gt;  :wq&lt;&#x2F;sub&gt;&lt;&#x2F;p&gt;
</description>
            </item>
        
            <item>
                <title>Fix Windows 10 terminals, use a Linux terminal</title>
                <pubDate>Mon, 08 Jul 2019 00:00:00 +0000</pubDate>
                <link>https://timvisee.com/blog/fix-windows-terminals-use-linux-terminal/</link>
                <guid>https://timvisee.com/blog/fix-windows-terminals-use-linux-terminal/</guid>
                <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;I feel handicapped in Windows terminals, here is why, and how I fixed it.&lt;&#x2F;em&gt;&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;
    &lt;a href=&quot;&#x2F;blog&#x2F;fix-windows-terminals-use-linux-terminal&#x2F;overview.png&quot; title=&quot;View full-size image&quot;&gt;
        
        
        
        &lt;img src=&quot;https:&amp;#x2F;&amp;#x2F;timvisee.com&amp;#x2F;processed_images&amp;#x2F;18853f2cc752ae0000.png&quot; &#x2F;&gt;
    &lt;&#x2F;a&gt;
&lt;&#x2F;p&gt;
&lt;p&gt;As a seasoned developer, I &lt;em&gt;live&lt;&#x2F;em&gt; in the terminal on Linux machines.
Using a custom shell, &lt;code&gt;vim&lt;&#x2F;code&gt; as text&#x2F;code editor, &lt;code&gt;git&lt;&#x2F;code&gt; through its CLI,
&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;timvisee&#x2F;dotfiles&quot;&gt;&lt;code&gt;dotfiles&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; to sync settings across devices.
Everything is customized to my likings and styled with a nice color scheme.
All of it in a dark, text-based window on my screen.&lt;&#x2F;p&gt;
&lt;p&gt;Once you get used to your command-line tools, it&#x27;s a serious joy to
work with. It&#x27;s a way to interface with your machine in a super-efficient and
expressive manner. As you can probably imagine, it can be pretty frustrating
when you don&#x27;t have access to the tools you know and love.&lt;&#x2F;p&gt;
&lt;p&gt;I sometimes use a Windows machine, for work or for building Windows-supported
software. Sadly, I feel pretty handicapped on this operating system, to be
frank. I can&#x27;t get comfortable (and I&#x27;m super OCD for that matter).
The overall experience always appears to be subpar to what I&#x27;m used to.&lt;&#x2F;p&gt;
&lt;span id=&quot;continue-reading&quot;&gt;&lt;&#x2F;span&gt;
&lt;p&gt;Through some testing, I&#x27;ve located this to be a problem with the terminals on
Windows. Though before the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Windows_Subsystem_for_Linux&quot;&gt;WSL&lt;&#x2F;a&gt; era, running Linux tooling on Windows was
literally unthinkable, the situation has already improved a lot. Almost every
Linux tool works somewhat out of the box. Installing and configuring your
software using &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;github.com&#x2F;timvisee&#x2F;dotfiles&quot;&gt;dotfiles&lt;&#x2F;a&gt; became a much better experience as well.
The terminals on Windows still feel mediocre, it just isn&#x27;t there yet.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;I should note that this isn&#x27;t a problem for light terminal usage in Windows
10 these days. When invoking simple commands through SSH, everything works
beautifully. This is about using heavily personalized tooling, and as you
can probably tell, I&#x27;m somewhat of a power user in this regard. Though, this
might become useful in the future.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h3 id=&quot;the-problems&quot;&gt;The problems
    &lt;a class=&quot;anchor&quot; href=&quot;#the-problems&quot; aria-label=&quot;Anchor link for: the-problems&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h3&gt;
&lt;p&gt;Throughout the past year, I&#x27;ve tried using a &lt;strong&gt;lot&lt;&#x2F;strong&gt; of different terminals
after giving up on the terminal included with &lt;code&gt;bash&lt;&#x2F;code&gt; on Windows.
Some of them include: ConEmu, hyper, Cmder, Terminus &amp;amp; PuTTY, with various
troublesome configuration attempts. I was never able to achieve the same
experience as I&#x27;ve had on Linux or macOS, have always encountered weird
shenanigans and was never really satisfied.&lt;&#x2F;p&gt;
&lt;p&gt;Personally, I can generalize the usual problems to the following:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;color schemes are problematic, and usually, look different than its Linux
counterpart&lt;&#x2F;li&gt;
&lt;li&gt;terminals on Windows appear &lt;em&gt;sloooow&lt;&#x2F;em&gt;, as a &lt;code&gt;vim&lt;&#x2F;code&gt; user you expect things to be
instant&lt;&#x2F;li&gt;
&lt;li&gt;garbled output, no proper &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;ANSI_escape_code&quot;&gt;ANSI&lt;&#x2F;a&gt; support&lt;&#x2F;li&gt;
&lt;li&gt;some bindings don&#x27;t work&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;p&gt;With some more specific examples throughout the different terminals:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;weird lines between characters, random underlined text&lt;&#x2F;li&gt;
&lt;li&gt;everything looks darker than it should be&lt;&#x2F;li&gt;
&lt;li&gt;color channels are flipped&lt;&#x2F;li&gt;
&lt;li&gt;some special characters are not rendered at all&lt;&#x2F;li&gt;
&lt;li&gt;no support for &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;stackoverflow.com&#x2F;a&#x2F;10039347&#x2F;1000145&quot;&gt;&lt;code&gt;xterm-256color&lt;&#x2F;code&gt;&lt;&#x2F;a&gt; at all&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h3 id=&quot;simple-solution&quot;&gt;Simple solution
    &lt;a class=&quot;anchor&quot; href=&quot;#simple-solution&quot; aria-label=&quot;Anchor link for: simple-solution&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h3&gt;
&lt;p&gt;The solution to these problems honestly was quite simple, much more so than I
initially thought:&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Just run a Linux terminal you&#x27;re familiar with, on Windows.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;Yes, seriously. Why not use a Linux terminal, if you can&#x27;t get Windows
terminals to behave? Because this is Windows, not Linux? Nope!&lt;&#x2F;p&gt;
&lt;p&gt;Some effort is required to get this up and running, which is what I&#x27;ll guide you
through in the following section. Don&#x27;t worry, this won&#x27;t be hard and
shouldn&#x27;t take more than 15 minutes.&lt;&#x2F;p&gt;
&lt;h2 id=&quot;linux-terminal-on-windows-10&quot;&gt;Linux terminal on Windows 10
    &lt;a class=&quot;anchor&quot; href=&quot;#linux-terminal-on-windows-10&quot; aria-label=&quot;Anchor link for: linux-terminal-on-windows-10&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h2&gt;
&lt;p&gt;Before we start, make sure you&#x27;re running an up-to-date Windows 10 instance,
and you need to have administrator rights. That&#x27;s all, and you&#x27;re good to go.&lt;&#x2F;p&gt;
&lt;p&gt;We&#x27;ll be going through the following five easy steps:&lt;&#x2F;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;timvisee.com&#x2F;blog&#x2F;fix-windows-terminals-use-linux-terminal&#x2F;#enable-wsl&quot;&gt;Enable WSL, install Ubuntu&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;timvisee.com&#x2F;blog&#x2F;fix-windows-terminals-use-linux-terminal&#x2F;#install-terminal&quot;&gt;Install XFCE terminal&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;timvisee.com&#x2F;blog&#x2F;fix-windows-terminals-use-linux-terminal&#x2F;#install-x&quot;&gt;Install X server&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;timvisee.com&#x2F;blog&#x2F;fix-windows-terminals-use-linux-terminal&#x2F;#run-terminal&quot;&gt;Run XFCE terminal&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;timvisee.com&#x2F;blog&#x2F;fix-windows-terminals-use-linux-terminal&#x2F;#useful-shortcuts&quot;&gt;Create useful shortcuts&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ol&gt;
&lt;h3 id=&quot;enable-wsl&quot;&gt;1. Enable WSL, install Ubuntu
    &lt;a class=&quot;anchor&quot; href=&quot;#enable-wsl&quot; aria-label=&quot;Anchor link for: enable-wsl&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h3&gt;
&lt;p&gt;Alright. The first big part is to get Linux software running on Windows in the
first place. Lucky for us, Windows has &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Windows_Subsystem_for_Linux&quot;&gt;WSL&lt;&#x2F;a&gt; these days, making this a
breeze.&lt;&#x2F;p&gt;
&lt;p&gt;To start, you must &lt;strong&gt;enable WSL&lt;&#x2F;strong&gt; on your installation. Microsoft&#x27;s own
guide perfectly describes how this is done:&lt;br &#x2F;&gt;
&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;wsl&#x2F;install-win10&quot;&gt;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;wsl&#x2F;install-win10&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Once that is finished, you should &lt;strong&gt;install a Linux distribution&lt;&#x2F;strong&gt; that
provides Linux tooling we need.  We&#x27;ll be using the &lt;strong&gt;Ubuntu&lt;&#x2F;strong&gt; distribution
for this, which is most commonly used. (You may choose a different distro,
although some of the following commands will be different.) Ubuntu is
installed through the Microsoft Store, also described in
&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;docs.microsoft.com&#x2F;en-us&#x2F;windows&#x2F;wsl&#x2F;install-win10#install-your-linux-distribution-of-choice&quot;&gt;this&lt;&#x2F;a&gt; guide.&lt;&#x2F;p&gt;
&lt;p&gt;WSL &amp;amp; Linux: check ☑️&lt;&#x2F;p&gt;
&lt;p&gt;Let&#x27;s continue.&lt;&#x2F;p&gt;
&lt;h3 id=&quot;install-terminal&quot;&gt;2. Install XFCE terminal
    &lt;a class=&quot;anchor&quot; href=&quot;#install-terminal&quot; aria-label=&quot;Anchor link for: install-terminal&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h3&gt;
&lt;p&gt;Now you can pick a Linux terminal you want to use. We&#x27;ll be
using the terminal included with the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;xfce.org&#x2F;&quot;&gt;XFCE&lt;&#x2F;a&gt; desktop in this guide. It&#x27;s a
excellent versatile terminal, that is efficient, has superb color scheme
support, and has all the options you need. Choosing some different you have
experience with is fine as well, of course.&lt;&#x2F;p&gt;
&lt;p&gt;To &lt;strong&gt;install XFCE terminal&lt;&#x2F;strong&gt;, we&#x27;ll use the Ubuntu package manager. Open the start
menu, and search for &lt;code&gt;bash&lt;&#x2F;code&gt;. This should bring up a terminal window running
Linux through WSL with a &lt;code&gt;bash&lt;&#x2F;code&gt; shell. Invoke the following two commands:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#191919;color:#f8f8f2;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;sudo&lt;&#x2F;span&gt;&lt;span&gt; apt update
&lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;sudo&lt;&#x2F;span&gt;&lt;span&gt; apt install xfce4-terminal
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;
    &lt;a href=&quot;install_xfce.png&quot; title=&quot;View full-size image&quot;&gt;
        
        
        
        &lt;img src=&quot;https:&amp;#x2F;&amp;#x2F;timvisee.com&amp;#x2F;processed_images&amp;#x2F;4b831c433904153600.png&quot; &#x2F;&gt;
    &lt;&#x2F;a&gt;
&lt;&#x2F;p&gt;
&lt;p&gt;You won&#x27;t be able to use the installed terminal just yet, because Linux in WSL
has no way to draw a window on your screen at this time. We&#x27;ll fix that in the
next step.&lt;&#x2F;p&gt;
&lt;p&gt;A proper terminal: check ☑️&lt;&#x2F;p&gt;
&lt;h3 id=&quot;install-x&quot;&gt;3. Install X server
    &lt;a class=&quot;anchor&quot; href=&quot;#install-x&quot; aria-label=&quot;Anchor link for: install-x&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h3&gt;
&lt;p&gt;Graphical Linux systems commonly use the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;X_Window_System&quot;&gt;X&lt;&#x2F;a&gt; Window System (a.k.a. X11), used
to manage and draw application windows on the screen. This system is very
flexible &amp;amp; modular, which comes to good use in our case. X has various server
implementations, not just for Linux but also for Windows, acting as a system for
rendering windows.&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Random fun fact: you can even draw windows over the network with X, to an
external machine.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;p&gt;We need to &lt;strong&gt;install an X server&lt;&#x2F;strong&gt; on our Windows system and tell Linux in WSL
to draw application windows to it. Guess what, this is the last installation
step required for showing the terminal window!&lt;&#x2F;p&gt;
&lt;p&gt;In this guide, we&#x27;ll be using &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;sourceforge.net&#x2F;projects&#x2F;vcxsrv&#x2F;&quot;&gt;&lt;strong&gt;VcXsrv&lt;&#x2F;strong&gt;&lt;&#x2F;a&gt;, but other implementations
should work similarly. Visit its project page, download and install it:&lt;br &#x2F;&gt;
&lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;sourceforge.net&#x2F;projects&#x2F;vcxsrv&#x2F;&quot;&gt;sourceforge.net&#x2F;projects&#x2F;vcxsrv&lt;&#x2F;a&gt;&lt;&#x2F;p&gt;
&lt;p&gt;Ability to render the terminal window on the screen: check ☑️&lt;&#x2F;p&gt;
&lt;h3 id=&quot;run-terminal&quot;&gt;4. Run XFCE terminal
    &lt;a class=&quot;anchor&quot; href=&quot;#run-terminal&quot; aria-label=&quot;Anchor link for: run-terminal&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h3&gt;
&lt;p&gt;Now comes the fun part: actually starting and using the terminal.&lt;&#x2F;p&gt;
&lt;p&gt;You must start the X server we installed, tell applications in Linux to draw to
it, and the terminal is ready to start. Note that this is required after each login.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;start-vcxsrv&quot;&gt;Start VcXsrv
    &lt;a class=&quot;anchor&quot; href=&quot;#start-vcxsrv&quot; aria-label=&quot;Anchor link for: start-vcxsrv&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h4&gt;
&lt;p&gt;First, &lt;strong&gt;start the VcXsrv server&lt;&#x2F;strong&gt; we have installed. An icon should have
appeared on your desktop, or you might find it through the start menu (named
&#x27;Xlaunch&#x27;). It will then ask us for some settings through a wizard:&lt;&#x2F;p&gt;
&lt;p&gt;Pick &#x27;Multiple windows&#x27; for now, you can experiment with other options later.
Leave the &#x27;Display number&#x27; value at &lt;code&gt;-1&lt;&#x2F;code&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;
    &lt;a href=&quot;vcxsrv1.png&quot; title=&quot;View full-size image&quot;&gt;
        
        
        
        &lt;img src=&quot;https:&amp;#x2F;&amp;#x2F;timvisee.com&amp;#x2F;processed_images&amp;#x2F;22873c0cec0983d200.png&quot; &#x2F;&gt;
    &lt;&#x2F;a&gt;
&lt;&#x2F;p&gt;
&lt;p&gt;Just &#x27;Start no client&#x27; for now, which allows us to show any number of Linux
application windows. You can always start the terminal directly through here
at a later time.&lt;&#x2F;p&gt;
&lt;p&gt;
    &lt;a href=&quot;vcxsrv2.png&quot; title=&quot;View full-size image&quot;&gt;
        
        
        
        &lt;img src=&quot;https:&amp;#x2F;&amp;#x2F;timvisee.com&amp;#x2F;processed_images&amp;#x2F;38d45c9534130c4f00.png&quot; &#x2F;&gt;
    &lt;&#x2F;a&gt;
&lt;&#x2F;p&gt;
&lt;p&gt;We want to sync the clipboard to make life easier.&lt;&#x2F;p&gt;
&lt;p&gt;
    &lt;a href=&quot;vcxsrv3.png&quot; title=&quot;View full-size image&quot;&gt;
        
        
        
        &lt;img src=&quot;https:&amp;#x2F;&amp;#x2F;timvisee.com&amp;#x2F;processed_images&amp;#x2F;d49219cb43df2bb900.png&quot; &#x2F;&gt;
    &lt;&#x2F;a&gt;
&lt;&#x2F;p&gt;
&lt;p&gt;Click &#x27;Next&#x27; one more time and start the server.&lt;&#x2F;p&gt;
&lt;p&gt;Start the X server: check ☑️&lt;&#x2F;p&gt;
&lt;h4 id=&quot;configure-x-server-address&quot;&gt;Configure X server address
    &lt;a class=&quot;anchor&quot; href=&quot;#configure-x-server-address&quot; aria-label=&quot;Anchor link for: configure-x-server-address&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h4&gt;
&lt;p&gt;After that, the X server starts and a taskbar tray icon should appear.
This is useful because it tells us the address the server is running at.
Right-clicking allows you to kill the server as well.&lt;&#x2F;p&gt;
&lt;p&gt;
    &lt;a href=&quot;toolbar_icon.png&quot; title=&quot;View full-size image&quot;&gt;
        
        
        
        &lt;img src=&quot;https:&amp;#x2F;&amp;#x2F;timvisee.com&amp;#x2F;processed_images&amp;#x2F;da7313e7fa240c9500.png&quot; &#x2F;&gt;
    &lt;&#x2F;a&gt;
&lt;&#x2F;p&gt;
&lt;p&gt;Our X server is running at &lt;code&gt;0.0&lt;&#x2F;code&gt;, chosen by the server because we set the
display number to &lt;code&gt;-1&lt;&#x2F;code&gt;. We need the number before the &lt;code&gt;.&lt;&#x2F;code&gt;, being &lt;code&gt;0&lt;&#x2F;code&gt; in this
case, and have to &lt;strong&gt;configure this in the Linux environment&lt;&#x2F;strong&gt;.&lt;&#x2F;p&gt;
&lt;p&gt;Open a &lt;code&gt;bash&lt;&#x2F;code&gt; shell again through the Windows start menu to access the Linux
environment. And set the &lt;code&gt;DISPLAY&lt;&#x2F;code&gt; environment variable to &lt;code&gt;:0&lt;&#x2F;code&gt;, for our X
server address:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#191919;color:#f8f8f2;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;export &lt;&#x2F;span&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;DISPLAY&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ff5e5e;&quot;&gt;=&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;:0
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;Configured the X server address: check ☑️&lt;&#x2F;p&gt;
&lt;h4 id=&quot;start-the-terminal&quot;&gt;Start the terminal
    &lt;a class=&quot;anchor&quot; href=&quot;#start-the-terminal&quot; aria-label=&quot;Anchor link for: start-the-terminal&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h4&gt;
&lt;p&gt;This finally makes your system ready to actually start the terminal. &lt;strong&gt;Invoke
the following command&lt;&#x2F;strong&gt; and see the magic happen:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#191919;color:#f8f8f2;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;xfce4-terminal
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;
    &lt;a href=&quot;start_xfce.png&quot; title=&quot;View full-size image&quot;&gt;
        
        
        
        &lt;img src=&quot;https:&amp;#x2F;&amp;#x2F;timvisee.com&amp;#x2F;processed_images&amp;#x2F;6e808e1add847e9600.png&quot; &#x2F;&gt;
    &lt;&#x2F;a&gt;
&lt;&#x2F;p&gt;
&lt;p&gt;Oh yes! There it is, the XFCE Linux terminal on your Windows system in all its
glory. The terminal has sane defaults, but I recommend to take a quick look
through its settings anyway to pick the desired color scheme.&lt;&#x2F;p&gt;
&lt;p&gt;
    &lt;a href=&quot;xfce_colors.png&quot; title=&quot;View full-size image&quot;&gt;
        
        
        
        &lt;img src=&quot;https:&amp;#x2F;&amp;#x2F;timvisee.com&amp;#x2F;processed_images&amp;#x2F;c5b5d6e66e83375400.png&quot; &#x2F;&gt;
    &lt;&#x2F;a&gt;
&lt;&#x2F;p&gt;
&lt;p&gt;Your terminal is now ready to use to its full potential. Happy hacking!&lt;&#x2F;p&gt;
&lt;h3 id=&quot;useful-shortcuts&quot;&gt;5. Create useful shortcuts
    &lt;a class=&quot;anchor&quot; href=&quot;#useful-shortcuts&quot; aria-label=&quot;Anchor link for: useful-shortcuts&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h3&gt;
&lt;p&gt;Okay, we&#x27;re not quite done yet.&lt;&#x2F;p&gt;
&lt;p&gt;As you might have noticed, these last few steps are required after each login,
which is cumbersome. The X server must be started, and you need to set
the &lt;code&gt;DISPLAY&lt;&#x2F;code&gt; variable for each &lt;code&gt;bash&lt;&#x2F;code&gt; shell you open from Windows. Though the
following steps are not required, it is highly recommended you follow them.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;vcxsrv-configuration-file-shortcut&quot;&gt;VcXsrv configuration file shortcut
    &lt;a class=&quot;anchor&quot; href=&quot;#vcxsrv-configuration-file-shortcut&quot; aria-label=&quot;Anchor link for: vcxsrv-configuration-file-shortcut&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h4&gt;
&lt;p&gt;It is possible to create a configuration file for VcXsrv, to instantly start the
server without going through the wizard again and again.&lt;&#x2F;p&gt;
&lt;p&gt;To do this, go through the wizard one last time. You might want to use &lt;code&gt;0&lt;&#x2F;code&gt; as
&#x27;Display number&#x27; (instead of &lt;code&gt;-1&lt;&#x2F;code&gt;) to ensure you&#x27;re always starting the server
on a consistent address. On the final wizard screen, a &#x27;Save configuration&#x27;
button appears, click it and save it in an easy-to-access place such as your
desktop as it will act as shortcut.&lt;&#x2F;p&gt;
&lt;p&gt;
    &lt;a href=&quot;vcxsrv4.png&quot; title=&quot;View full-size image&quot;&gt;
        
        
        
        &lt;img src=&quot;https:&amp;#x2F;&amp;#x2F;timvisee.com&amp;#x2F;processed_images&amp;#x2F;ba800d3341c48d4300.png&quot; &#x2F;&gt;
    &lt;&#x2F;a&gt;
&lt;&#x2F;p&gt;
&lt;p&gt;Double-clicking the created configuration file&#x2F;shortcut should start the
server, and a tray icon should appear.&lt;&#x2F;p&gt;
&lt;h4 id=&quot;xfce-terminal-shortcut&quot;&gt;XFCE terminal shortcut
    &lt;a class=&quot;anchor&quot; href=&quot;#xfce-terminal-shortcut&quot; aria-label=&quot;Anchor link for: xfce-terminal-shortcut&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h4&gt;
&lt;p&gt;We can make starting the terminal easier by creating a custom shortcut.
Right-click on your desktop or an Explorer window to create a new shortcut:&lt;&#x2F;p&gt;
&lt;p&gt;
    &lt;a href=&quot;create_shortcut.png&quot; title=&quot;View full-size image&quot;&gt;
        
        
        
        &lt;img src=&quot;https:&amp;#x2F;&amp;#x2F;timvisee.com&amp;#x2F;processed_images&amp;#x2F;06185ec68ae6820400.png&quot; &#x2F;&gt;
    &lt;&#x2F;a&gt;
&lt;&#x2F;p&gt;
&lt;p&gt;We&#x27;ll start &lt;code&gt;bash&lt;&#x2F;code&gt;, and automatically invoke the commands we ran
&lt;a href=&quot;https:&#x2F;&#x2F;timvisee.com&#x2F;blog&#x2F;fix-windows-terminals-use-linux-terminal&#x2F;#configure-x-server-address&quot;&gt;before&lt;&#x2F;a&gt;. Fill in the following command in the
&#x27;Location&#x27; field for this shortcut:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#191919;color:#f8f8f2;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;bash&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fc9354;&quot;&gt; -c &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;export DISPLAY=:0; xfce4-terminal -e bash&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;
    &lt;a href=&quot;shortcut_path.png&quot; title=&quot;View full-size image&quot;&gt;
        
        
        
        &lt;img src=&quot;https:&amp;#x2F;&amp;#x2F;timvisee.com&amp;#x2F;processed_images&amp;#x2F;8926de208b75ecfa00.png&quot; &#x2F;&gt;
    &lt;&#x2F;a&gt;
&lt;&#x2F;p&gt;
&lt;p&gt;Hit &#x27;Next&#x27;, pick a fun name and you&#x27;re done.&lt;&#x2F;p&gt;
&lt;p&gt;Double-clicking the shortcut you&#x27;ve created should automatically open a new
&lt;em&gt;proper&lt;&#x2F;em&gt; terminal window. Hurray!&lt;&#x2F;p&gt;
&lt;p&gt;Windows automatically spawns a window for the &lt;code&gt;bash&lt;&#x2F;code&gt; command we&#x27;re running
through the shortcut, causing two windows to show up. This is annoying.
Luckily we can minimize this unused window by default. Right-click on the
shortcut, and hit &#x27;Properties&#x27;. Set the &#x27;Run&#x27; option to &#x27;Minimized&#x27;:&lt;&#x2F;p&gt;
&lt;p&gt;
    &lt;a href=&quot;shortcut_minimized.png&quot; title=&quot;View full-size image&quot;&gt;
        
        
        
        &lt;img src=&quot;https:&amp;#x2F;&amp;#x2F;timvisee.com&amp;#x2F;processed_images&amp;#x2F;8a42716bb3bb1afc00.png&quot; &#x2F;&gt;
    &lt;&#x2F;a&gt;
&lt;&#x2F;p&gt;
&lt;blockquote&gt;
&lt;p&gt;Not showing the &lt;code&gt;bash&lt;&#x2F;code&gt; window at all is also possible with a workaround,
but won&#x27;t be covered in this guide.&lt;&#x2F;p&gt;
&lt;&#x2F;blockquote&gt;
&lt;h2 id=&quot;tips-tricks&quot;&gt;Tips &amp;amp; Tricks
    &lt;a class=&quot;anchor&quot; href=&quot;#tips-tricks&quot; aria-label=&quot;Anchor link for: tips-tricks&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h2&gt;
&lt;p&gt;Here are some tips, tricks, and notices you might find useful.&lt;&#x2F;p&gt;
&lt;p&gt;You can extend the command used for the shortcut to automatically open a specific
Linux program or to start an &lt;code&gt;ssh&lt;&#x2F;code&gt; session. You can create multiple different
shortcuts as well. Here&#x27;s an example to immediately start a &lt;code&gt;ssh&lt;&#x2F;code&gt; session I
commonly use:&lt;&#x2F;p&gt;
&lt;pre data-lang=&quot;bash&quot; style=&quot;background-color:#191919;color:#f8f8f2;&quot; class=&quot;language-bash &quot;&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span style=&quot;color:#e9fdac;&quot;&gt;bash&lt;&#x2F;span&gt;&lt;span style=&quot;font-style:italic;color:#fc9354;&quot;&gt; -c &lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#fbe3bf;&quot;&gt;export DISPLAY=:0; xfce4-terminal -e &amp;quot;bash -c \&amp;quot;ssh root@work.lan\&amp;quot;&amp;quot;&lt;&#x2F;span&gt;&lt;span style=&quot;color:#ffffff;&quot;&gt;&amp;#39;
&lt;&#x2F;span&gt;&lt;&#x2F;code&gt;&lt;&#x2F;pre&gt;
&lt;p&gt;You can set the &lt;code&gt;DISPLAY&lt;&#x2F;code&gt; environment variable by default, by appending the &lt;code&gt;export DISPLAY=:0&lt;&#x2F;code&gt; line to the &lt;code&gt;~&#x2F;.bashrc&lt;&#x2F;code&gt; file through your &lt;code&gt;bash&lt;&#x2F;code&gt; shell.&lt;&#x2F;p&gt;
&lt;p&gt;You can use other graphical Linux software as well after setting the &lt;code&gt;DISPLAY&lt;&#x2F;code&gt;
environment variable.&lt;&#x2F;p&gt;
&lt;p&gt;If Linux applications don&#x27;t show up, and the shortcut immediately quits, you
have probably configured an incorrect X server address or did not configure it
at all. Review the &lt;a href=&quot;https:&#x2F;&#x2F;timvisee.com&#x2F;blog&#x2F;fix-windows-terminals-use-linux-terminal&#x2F;#configure-x-server-address&quot;&gt;Configure X server address&lt;&#x2F;a&gt;
section.&lt;&#x2F;p&gt;
&lt;p&gt;Here&#x27;s a simple final checklist for all the steps to get a Linux terminal
working:&lt;&#x2F;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;timvisee.com&#x2F;blog&#x2F;fix-windows-terminals-use-linux-terminal&#x2F;#enable-wsl&quot;&gt;enable WSL, install Ubuntu&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;timvisee.com&#x2F;blog&#x2F;fix-windows-terminals-use-linux-terminal&#x2F;#install-terminal&quot;&gt;install XFCE terminal&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;&lt;a href=&quot;https:&#x2F;&#x2F;timvisee.com&#x2F;blog&#x2F;fix-windows-terminals-use-linux-terminal&#x2F;#install-x&quot;&gt;install X server&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;for each login: &lt;a href=&quot;https:&#x2F;&#x2F;timvisee.com&#x2F;blog&#x2F;fix-windows-terminals-use-linux-terminal&#x2F;#start-vcxsrv&quot;&gt;start VcXsrv&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;for each &lt;code&gt;bash&lt;&#x2F;code&gt; shell: &lt;a href=&quot;https:&#x2F;&#x2F;timvisee.com&#x2F;blog&#x2F;fix-windows-terminals-use-linux-terminal&#x2F;#configure-x-server-address&quot;&gt;configure X server address&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;li&gt;for each &lt;code&gt;bash&lt;&#x2F;code&gt; shell: &lt;a href=&quot;https:&#x2F;&#x2F;timvisee.com&#x2F;blog&#x2F;fix-windows-terminals-use-linux-terminal&#x2F;#start-the-terminal&quot;&gt;start the terminal&lt;&#x2F;a&gt;&lt;&#x2F;li&gt;
&lt;&#x2F;ul&gt;
&lt;h2 id=&quot;final-thoughts&quot;&gt;Final thoughts
    &lt;a class=&quot;anchor&quot; href=&quot;#final-thoughts&quot; aria-label=&quot;Anchor link for: final-thoughts&quot;&gt;&lt;&#x2F;a&gt;

&lt;&#x2F;h2&gt;
&lt;p&gt;This solution isn&#x27;t ideal. It takes effort to get up and running, and opening
a new terminal isn&#x27;t as easy as with other terminals. But for me, this is a
solution that gives me the best terminal experience I&#x27;ve had on Windows. It
works like a charm, and it feels super &lt;em&gt;comfy&lt;&#x2F;em&gt;. That is important.&lt;&#x2F;p&gt;
&lt;p&gt;
    &lt;a href=&quot;workspace.png&quot; title=&quot;View full-size image&quot;&gt;
        
        
        
        &lt;img src=&quot;https:&amp;#x2F;&amp;#x2F;timvisee.com&amp;#x2F;processed_images&amp;#x2F;7fe353f34a389a3200.png&quot; &#x2F;&gt;
    &lt;&#x2F;a&gt;
&lt;&#x2F;p&gt;
&lt;p&gt;Honestly, I find it kind of interesting, that almost every terminal on a Linux
or macOS based system works flawlessly for any tooling with no configuration.
However, on Windows, I don&#x27;t see this quality, for something that seems so
simple: rendering monospaced text on a screen.&lt;&#x2F;p&gt;
&lt;p&gt;Let&#x27;s hope the terminal situation on Windows improves. A lot has been getting
better lately since WSL was introduced, and many more people started experiencing
these itches than before since Linux on Windows became a viable thing.
I wonder what the &lt;a rel=&quot;noopener&quot; target=&quot;_blank&quot; href=&quot;https:&#x2F;&#x2F;devblogs.microsoft.com&#x2F;commandline&#x2F;introducing-windows-terminal&#x2F;&quot;&gt;upcoming&lt;&#x2F;a&gt; Windows terminal will bring to
the table.&lt;&#x2F;p&gt;
&lt;p&gt;I won&#x27;t be going back to Windows anytime soon myself, but at least this provides
a terminal I&#x27;m happy with when I &lt;em&gt;need&lt;&#x2F;em&gt; to use a Windows machine.&lt;&#x2F;p&gt;
&lt;p&gt;As always: &lt;em&gt;Hope this helps!&lt;&#x2F;em&gt; &lt;sub&gt;  :wq&lt;&#x2F;sub&gt;&lt;&#x2F;p&gt;
</description>
            </item>
        
    </channel>
</rss>

