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:
  1. Open ~/.bashrc
  2. Go to the end of the file
  3. Add following lines (at the end)
    alias docker=docker.exe
    alias docker-compose=docker-compose.exe
Docker

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:
  1. Download the executable
  2. Save the .exe somewhere
  3. Change the settings of your IDEs to use wslgit.exe as git executable

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.exe
3. Click on compatibility
4. Click on HDPI-Settings
5. 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: failed to commit changes to dconf: Failed to execute child process “dbus-launch” (No such file or directory) Dont you worry child! It is easy to fix. We just need to install the dbus-service and run execute it:
sudo apt-get install dbus-x11
sudo service dbus start
That’s all! The make it more convenient to use we are going to write a small script to launch it. Just open VSCode and copy and paste following:
args = "-c" & " -l " & """GDK_SCALE=3 DISPLAY=:0 tilix"""

WScript.CreateObject("Shell.Application").ShellExecute "bash", args, "", "open", 0
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!
running tilix

About The Author

Hey;) I'm just a regular guy. Do I spend my free time writing a blog? Or to watch live streams from the Google I/O, Microsoft Build etc.? Definitely! Have I decided to study computer science so that I can work as a software developer? Maybe! Am I currently working for 1&1? Yes. Am I the only one of the Billige Plätze who lives in Munich? for sure! But in the end it all comes down to one thing, I'm a cat person!

Leave a Reply

Your email address will not be published. Required fields are marked *