5 Things I love about WSL

I got a new PC and love it! But a new PC also means a whole new setup and a lot of work. One of the first things I’ve setup has been the Windows Subsystem for Linux. I know I am a developer and most of you would not expect me to work on a windows machine. Guys I must tell you windows is fucking awesome and with WSL it’s just getting more awesome! Here five things I really love about WSL

1. Interoperability

Starting with Windows build 14951 Microsoft added the possibility to (1) invoke Linux binaries from the Windows Console (2) invoke Windows binaries from the Linux Console and (3) sharing environment variables between Windows and Linux. Furthermore, with the Fall creates Update Microsoft include the windows path in the Linux $Path so it is easy to call windows binaries from Linux. So, to call Windows binaries from windows you just must type:

[binaries name].exe

For instance, you could open the windows file explorer at the current location of your windows console by simply calling:

explorer.exe .

launching explorer from the Linux Console

2. Docker

Okay now I gonna cheat but its so cool it deserves to be its own point. Due to the Interoperability between WSL and Windows you do not need to expose some creepy port or build complicated relay between WSL and Windows. You can just run “docker.exe” to use docker for windows inside your Linux console. Ok I admit this is not very practical since you have always to type “.exe”. But Linux is awesome and lets you define aliases so such things. All you need to do is:

3. WSLGIT

As mentioned in (1) you can execute windows binaries from the Linux console. As a result, you can open VSCode from the Linux Console. Here´s the catch: VSCode would still use Git for Windows. This is not really a problem and works. I really love to use git inside my Linux console, but I don’t want to manage two git installations on the same machine. One could argue that you could do the same trick as we did with docker and that’s true but this time we do is the other way round. There is a GitHub Project from andy-5 that is called WSLGIT. Basically, this project aims to provide a small executable that forwards arguments to git running inside Bash on Windows. All that needs to be done is:

4. X-Server for Windows

So, what can’t be done with WSL? Right you can not run graphical applications. Can`t you? That’s just partial true: You can use an implementation of X-Server for windows and forward it inside your bash. I use the Xming X Server. Simply download it and install it. After installation open XLaunch, select “Multiple Windows” and “Display Number 0” at the first screen. Select “Start no client” at the second screen. Select “Clipboard” and go forward. Now you can save this configuration and add it to your autostart folder. That why you never have to configure it again (even when we just used the default configuration 😉). Inside your Linux console you just must run

export DISPLAY=:0

and you are ready to go. Now you can start graphical applications!

Fixing HDPI

You may encounter the same problem as I did. My new PC got a UHD resolution and graphical applications running with Xming X Server are blurry. This is the fault of the windows compatibility mode that is scaling the application. To fix it you need:

1. Navigate to the installation folder of Xming 2. Open the Properties of Xming.exe3. Click on compatibility 4. Click on HDPI-Settings5. Override HDPI-Setting with application defaults

DPI-Settings

So, every Linux application is really small 😊. But don’t mind we can fix that inside Linux! If we use GTK application, we can just increase the GTK scaling factor by typing: export GDK_SCALE=3

The power of X-Server

5. Seamlessly using Linux

This sums it up, but I will show you what I mean by example. We gonna run Tilix, a tiling terminal emulator for Linux using GTK+ 3, as it would be a ordinary windows application. Note to do that, you need to follow the instructions under point (4). I’m assuming you already did that. To install Tilix we just need to type

sudo add-apt-repository ppa:webupd8team/terminix

sudo apt-get update

sudo apt-get install tilix

You might encounter some problems regarding the dbus service. For instance you could get a error message like this:

NOTE: if you don’t have UDH resolution you can remove following GDK_SCALE=3. Save the script under …Programms/Tilix and name it tilix.vbs. Now we need a second script a simple bat file that we use to invoke our first script:

WScript tilix.vbs

Almost done! We can now send the bat script to the deskop and get a nice clickable icon that can be used to launch Tilix. If you put it in the Startmenu folder you can even use it from the Startmenu in windows 10!