Cool Colors in WSL/Bash

As some may know, before joining Microsoft to work on the C# compiler I was a pretty dedicated Linux user (Arch, thanks for asking) and despite finding replacements for a number of my Linux workflow standbys, I've never found a good substitute for the Unix shell. Enter the Windows Subsystem for Linux AKA "Bash on Windows" AKA "GNU/NT". It's not yet my daily driver, but it's getting closer every update.

One great new feature was 24-bit color. It may seem petty, but when your entire user interface is text, every small delineation makes a huge difference in user experience. One nit is that, while it's easy for programs to output text in full color with this change, it's not easy for you, the user, to change the color palette. What's the difference, you ask? A color code can be used to explicitly change the current foreground or background color to a specific shade. The color palette, however, indicates what the default color shades are. For instance, if a program says, "change the foreground color to red", but doesn't explicitly mention a shade of red, the shade of red that gets chosen is whatever red maps to in the color palette.

It practice, most terminal programs don't specify the exact color shade, but instead use on of the standard colors. There are two big benefits to that. First, you don't have to know exactly what color shades the terminal supports and, second, you don't run the risk of your chosen color shade not being visible against the other color shades in the terminal (assuming the user set their palette properly).

So WSL lets programs use a wide gamut of colors, but doesn't let them easily customize their color palette, often referred to as a theme. Luckily, Linux has a long history of theme customization, so all WSL needs is a bridge from the Linux tools to the Windows tools. Enter xres2lnk. This is a program I wrote to translate colors from a standard XResources file (a common format for Unix terminals) into a shortcut file. Why a shortcut file? Well, aside from the registry it's the only way to save customized colors for a console on Windows and in my experience it's much easier to save and sync between multiple computers. You can also save different color themes to different shortcuts, so you can use different color themes for different terminal sessions.

But, you say, I don't have an XResources file! Not to worry! Sites like https://github.com/mbadolato/iTerm2-Color-Schemes#screenshots, https://github.com/chriskempson/base16, and http://terminal.sexy/ provide tons of themes in XResources format to download and try out. terminal.sexy even lets you customize the themes in an online color editor before exporting in XResources format.

In subsequent posts I'll detail more of my WSL customizations, but for now, if you're using WSL you have no excuses not to look good while doing it!

social