A Windows terminal that is Linux

Using Arch Linux at home and having switched to using OSX over the last couple of years for my professional development, I’ve grown more a more accustomed to having a rich CLI experience. It always felt like Windows left a lot to be desired in this regard. When PowerShell arrived on the scene, it made things better but the ecosystem just wasn’t as comprehensive and until the recent arrival of PowerShell Core it was very Windows centric. Cygwin was always another option, which would bring over many of the familiar tools but it’s lack of a full package manger makes it harder to just pluck community built tools.

Enter WSL (Windows Linux subsystem), which is essentially a full Linux distro minus a display manager but even that will be with us soon. It’s been available since 2016, so we’re not exactly covering the bleeding edge here but we will be discussing using WSL 2.0+ going forward.

That’s the shell covered, but another core piece in the puzzle for Windows was the lack of a good home grown terminal. We’ll be taking a look at Windows Terminal in this post. From my perspective it’s good enough for daily driving and taking a look at the roadmap It’s also only going to get better. I had used ConEmu previously which is more feature rich and feels more familiar to Iterm2, all the WSL goodness will be possible using either so choose your own poison.

Install Arch Linux in WSL

First we need to enable WSL, simply navigate to the windows features GUI

Enable the windows subsystem for Linux.

You now have a choice, of what distro you want to install, I’m going to use Arch which is slightly more difficult because it’s not available in the Windows Store at time of writing, in my opinion has the best package manager, it’s also what I run on my laptop so it just helps that it’s familiar.

Download and then follow the Arch WSL setup instructions. If you want to use another distro head over to the Microsoft store. Once installed, the distro should automatically appear and the Terminal new tab drop down.

One omission from the arch installation instructions is it doesn’t set your new user as the default. meaning you would need to su my-user-name every time you start using a new shell. This is a pain, also you certainly should just roam around as root! Get your user ID, it’ll likely be 1000 but best to check.

cat /etc/passwd

It’s the third number, explanation.

jps:x:1000:1000::/home/jps:/usr/bin/zsh

Now from a Windows PowerShell run.

Arch.exe config --default-uid 1000

Open a new session and you should be logged in as the default user, if you run pwd you’ll see you’ve been placed in that users home directory. You might be wondering well where the hell am I in relation to Windows. Run the following to open an explorer terminal to see find out.

explorer.exe .

Equally see our Windows partitions have been auto mounted for us by going by running

ls /mnt/

This is super powerful that we can so easily jump between the different OS’s underling file systems.

The next thing I would recommend to install is YAY it’s a wrapper/helper for pacman the package manger. It’ll simplify keeping the system up to date. One installed just run yay to update the system, this is one of the most appealing features of Arch, with this command you will be kept on the bleeding edge of everything you’ve installed.

So at the moment we have a full Linux distro running inside windows, we are no longer excluded from using all these great community tools that were available to just Linux or OSX users.

Fonts

To finesse our shell we’ll need some additional fonts installed in Windows, we’ll be installing the popular Powerline fonts, get the latest release from here extract and run the setup.ps1 script in an admin Powershell prompt. More detailed instructions can be found here.

Zsh

Zsh is a popular shell that comes with lots of advanced features but also masses of plugins that will let you tweak you terminal to your hearts content. For the sake of this tutorial we’ll use Spaceship Prompt it comes with an opinionated but sensible set of defaults, that will get you setup with minimal config.

Let’s install zsh using yay. You’ll want the one labelled yay/extra

yay zsh

Next install oh my zsh this is by far the most popular plug in manager for zsh.

 yay oh-my-zsh

And next up we are going to install Spaceship Prompt, yes, were nearly ready to go to space! Follow the oh my zsh instructions here.

You may have noticed nothings changed, as we are still in bash, we can go into zsh by simply running zsh but doing this every time isn’t ideal. Instead if we update the default shell for our user by going into

nano /etc/passwd 

Update the end of your user to point to the zsh shell, it should end up looking something like the following.

jps:x:1000:1000::/home/jps:/usr/bin/zsh

None of the settings we’ve just changed have anything to do with Windows, The real takeaway here is, whatever you decide to use, we can just follow the plain old Linux setup instructions.

Wrapping up

It’s pretty cool that we can now have an identical CLI experience on Linux, OSX and Windows. Learning one set of tooling and being able to use anywhere is such a bonus. We can just follow the Linux setup instructions and not worry about the fact we are actually running on Windows. Also it’s stage that running PowerShell in a Linux distro running natively inside Windows is a reality, if that’s your thing. This type of investment certainly makes Windows a much more attractive environment for developers and does put a question mark around the apple premium for development machines, if employers can persuade developers to give up the “developed on mac” status symbol is another thing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create your website with WordPress.com
Get started
%d bloggers like this: