Skip to main content

WSL + Explorer: the secret Terminal

Warning 

Please note that while you should read this blog post as a "joke", which hopefully will make you smile, all the commands are technically correct and should work for you too. With that being said, let the show begin. 

Introduction 

During the //BUILD 2018 conference, the session with Sarah and Tara showed how far WSL has come and, lucky for us, we can now see the replay or if you prefer reading, Tara has your back with a great recap
at the very end of their presentation, there is small but (very) impactful demo: the Windows Explorer context menu now has "Open Linux shell here":

Look at the past, you will see the future

Unfortunately I don't remember who showed this first (I do apologize), but there's a neet trick with Windows Explorer: if you type "cmd.exe" in the address bar, it will open a command prompt in the current directory.
So, with a little thinking and knowing that the shell is different from the Terminal application, then I tried it with a WSL distro: ubuntu1804.exe
Well, while it opens WSL Ubuntu, the path is set to $HOME ... not exactly what I wanted.
Then, I tried with WSL.exe directly: BINGO! that worked just fine.

Secret of the release notes

ok, it works great with the default WSL distro, but what if you want a different distro? Open the distro (i.e. Debian.exe) and then CD to the directory manually?
Well, the great minds at Microsoft brought us two little options with WSL that changed the rules of the game: --distribution and --exec

One WSL.exe to rule them all

before we can use the new options, we first need to know how the WSL distros are literally named.
For that, we have the (now) good ol' WSLConfig.exe command:
Now that we know the names, let's a try at the --distribution option and compare it to wsl.exe without options:

But the title mentions Explorer as a Terminal

and that's the last part of this blog post. As you might have read above, there's actually another option that will "invoke a single binary without a shell".
Let's try it out by renaming a file with WSL.exe and then rename it again with another distro (just for fun):
While this is a simple example, it already shows that the commands are executed successfully and the full path wasn't necessary as the invoked "binary" has the current path in its context.


BONUS: bring a Cloud-y taste to it

ultimately I managed to make something that might interest some Azure fans, MVPs or even (let's dream big here) Advocates:
And here is the script (please be kind, do not share with Jess "you know who" 😅):
A last easter egg is in the script itself: I'm using wslpath to ensure the path is in "Linux format".

Hope this will bring a smile at least.


>>> Nunix Out <<<

Comments

Post a Comment

Popular posts from this blog

Docker + WSL: Get 2 daemon for the price of 1

Introduction almost two years ago, Docker announced the capability of switching between the Linux and Windows containers "mode" (far from the right click that we have today). At that time, I wrote a blog post on how to run both daemons at the same time ( http://darthnunix.blogspot.ch/2016/10/docker-for-windows-2-daemons-enter-in.html ) Fast forward to 2018, and while we were blogging on how to get the TLS connection from WSL docker client with  Rory McCune  ( https://raesene.github.io/blog/2018/03/29/WSL-And-Docker/ ), another blog post, by Stefan Stranger drew my attention (read: blew my mind) as I was trying to reproduce the same: how could I "bind" the docker socket in WSL with the Docker for Windows Linux mode socket ( https://blogs.technet.microsoft.com/stefan_stranger/2018/04/02/access-my-docker-for-windows-kubernetes-cluster-from-debian-wsl/ ) From 1 to 2 daemon: DemonHunter mode achieved Now that we have all the required setup resources, let's b...

WSL: One Home to host them all

Introduction This blog post will explain how a single home mount can be shared accross all  the WSL instances. It was quite fun to find the idea and then make it happen. It will use all the tools currently available from WSL, so please don't expect a "Linux only" as Interopability will be heavily used. And before I start, here is my point of view about WSL: It's not only  Linux! It's different, just like GNU is different from Unix (yes I said it). We have finally the strength of both worlds combined. And while I do understand the "dev" aspect is meant to be reproducible in a Linux prod environment, the "ops" side is meant to take advantages of everything that can make the full environment feeling Home. Setup requirements In order to really enjoy this solution, I do recommend having 2 or more WSL distros installed or, if you fell like a real WSLCorsair, try @bketelsen crazy setup (I love it)! While the distros are downlo...

VSCode + WSL: the SSH way

The initial idea early 2017, Rich Turner made a demo where Visual Studio was used to develop C++ code, however the debugging environment targeted was WSL! With some magic, he showed something that he had forbidden from the initial release of WSL: writting directly to the WSL filesystem (still a big no-no actually). Of course, this triggered a lot of curiosity and the WSL Corsair had to loot from it too! SSH to save the day the biggest challenge was to find a way that not only could be easy to setup on both ends, and also would be approved  by the WSL team.  TLDR: if you use the Windows Path, You Die! #ThereBeDragons Another way, more Linux-oriented, needed to be used and hopefully a solution already existed and was simply waiting on being used: SSH🔐 The setup the setup is done in 2 distinct parts: Setup the SSH server on WSL Setup the SSH client on VSCode  While the SSH server is a standard procedure in Linux, finding the right  plugin for VSCode w...