Unix in Windows

The love hate rela­tion­ship that is the com­mand line and Win­dows. Any­one that has used Linux and has mas­tered the ter­mi­nal, feels very unpro­duc­tive on Win­dows. I for one feel like that. Too much click­ing, give me a TUI (Text User Inter­face)!

Recently Pow­er­Shell gave Unix peo­ple new hope, that times are chang­ing for the bet­ter. But are they? It’s def­i­nitely great leap for­ward, yet some­thing is still miss­ing. Microsoft gave us an awe­some new shell, but I want more. I have felt the real power of a good com­mand line, and I want it on Win­dows too.

What makes a per­fect shell? It all starts with the ter­mi­nal, the win­dow that ren­ders and dis­plays the text from the shell. Next comes the shell, the most impor­tant piece of the equa­tion, the thing that runs your com­mands. Finally comes the ecosys­tem of util­i­ties and bina­ries that will be exe­cuted in the shell. Each ele­ment plays a crit­i­cal role in the user experience. 

Ter­mi­nals

The piece of software/hardware that is respon­si­ble for dis­play­ing the out­put of the shell. In the early days this was a mon­i­tor and a key­board. Today, every­thing is done vir­tu­ally via soft­ware, called a ter­mi­nal emu­la­tor.

vt100

The ter­mi­nal is the GUI that dis­plays the text out­put of what­ever you are run­ning. It’s job is sim­ple, it for­mats the text on-screen and sends keyboard/mouse events back to run­ning appli­ca­tion. Every­thing oper­ates on a stream of char­ac­ters, either in or out.

On Linux you have over a dozen of dif­fer­ent ter­mi­nal appli­ca­tions avail­able to you, on Win­dows you have none. Yes, I said none. That’s because on Win­dows you don’t really have any ter­mi­nal emu­la­tors. You only have an API and a prim­i­tive “ter­mi­nal” like appli­ca­tion, which only looks like a terminal.

Both cmd.exe, powershell.exe and some com­mand line util­i­ties oper­ate by directly manip­u­lat­ing a API for ren­der­ing the text out­put in the “ter­mi­nal”. This isn’t nor­mally a prob­lem if you like the stan­dard “ter­mi­nal” pro­vided. But when you want to start using some­thing else that’s when the prob­lems arise.

The prob­lem

The shells on Win­dows don’t oper­ate on streams and pipes, which causes a lot of prob­lems when you want to use some­thing from the Unix world. Cyg­win is an attempt to bring tools from Linux into the Microsoft world, unfor­tu­nately it has some major per­for­mance issues.

Even with cyg­win and it’s issues, using both the Linux and Win­dows util­i­ties together is a pain. Because of the archi­tec­tural dif­fer­ences on how the con­sole works, nasty hacks have to be used in order for them to coöper­ate. When using Win­dows tools within cyg­win, a hid­den con­sole has to be opened to get the IO. Cur­rently cmd.exe and most of its tools work, but powershell.exe does not (at least not in inter­ac­tive mode). So using the ter­mi­nal emu­la­tors (such as MinTTY or Xterm) pro­vided by cyg­win is useless.

There are two notable native ter­mi­nals avail­able on Win­dows, but they use the same nasty hacks which slow down per­for­mance. The appli­ca­tions I’m talk­ing about are Console2 and ConEmu. ConEmu is a ter­mi­nal on steroids, but it’s per­for­mance is unbear­able when using Unix util­i­ties (draw­ing is very slow).

So in short you can­not use all the fancy cool things that you have on Linux, such as read­line, ANSI escape sequences, ncurses, the list goes on. You have to either be happy with the prim­i­tive ter­mi­nal that Microsoft pro­vides you, or just use cyg­win tools exclu­sively (ie you can­not fully uti­lize PowerShell).

You can­not marry all these thing into a sin­gle ter­mi­nal ses­sion. MinTTY for a fast cyg­win inter­face, while ConEmu for a nice Pow­er­Shell experience.

vworkspace_powershell_wallpaper

Pow­er­Shell

The foun­da­tion of a good com­mand line is the shell. It’s where you will spend most of your time. It’s pri­mary pur­pose is the exe­cu­tion of com­mands. But it should also be a pow­er­ful script­ing engine at the same time. For years this was not avail­able natively on Win­dows, not until Pow­er­Shell came out.

Pow­er­Shell brings a viable com­mand line inter­face to Win­dows, with pow­er­ful script­ing and automa­tion capa­bil­i­ties that it des­per­ately needed. Although its user expe­ri­ence in the inter­ac­tive mode can­not be com­pared to bash (or any other well estab­lished Unix shell). On the other hand its script­ing abil­i­ties are off the charts when it comes to automat­ing and manip­u­lat­ing Windows.

I would say that Pow­er­Shell is more of a script­ing lan­guage than a shell. It does func­tion per­fectly fine in inter­ac­tive mode, but it’s no bash. This makes me cranky.

Inter­ac­tiv­ity

command_prompt_256x256x32I’m very sad­dened by the inter­ac­tive mode of Pow­er­Shell. I say this because the amount of typ­ing and tab­bing needed to achieve some­thing is stren­u­ous. Every­thing is very ver­bose, mak­ing typ­ing com­mands labo­ri­ous. On the flip-side every­thing typed into the shell is rather read­able, even if you don’t know PowerShell.

Since I am very used to Unix com­mand line util­i­ties, not hav­ing them on Win­dows makes me very unpro­duc­tive. Not being able to use sed, awk, cut, tr, less, cat, etc is very annoy­ing. Unix phi­los­o­phy for util­i­ties is as fol­lows: do one thing, but do it well, and make it pip­pable. So com­plex com­mands can be assem­bled using mul­ti­ple com­mands pipped together. Pow­er­Shell for­tu­nately has that func­tion­al­ity, but they do it in a com­pletely dif­fer­ent way.

The biggest inno­va­tion that Pow­er­Shell brings to the com­mand line is that every­thing is an object. In bash or other shells, every­thing oper­ates on a stream. This inno­va­tion enables you to do very inter­est­ing things. You can now pass on objects with attrib­utes, mak­ing script­ing much more pow­er­ful. Not to men­tion the abil­ity to use C# and .NET within the shell.

As of ver­sion 3.0 of Pow­er­Shell, you can finally con­trol the com­mand line parser. For a bash per­son this is great, because via PSRead­Line you can emu­late the bash inter­face. Mean­ing you can have Emacs input mode, and tab com­ple­tion just like in bash. This for me is a killer fea­ture, and makes Win­dows usable.

Ecosys­tem

The last part of the equa­tion is the ecosys­tem of bina­ries and util­i­ties avail­able in the shell. With­out it, there is no use in hav­ing a shell or ter­mi­nal. It’s the bread and but­ter of the entire system.

This area was severely lack­ing in the Microsoft camp. You prac­ti­cally had noth­ing avail­able in the con­sole. You had old out­dated bina­ries that were from the DOS age. Pow­er­Shell forced the cre­ators of Win­dows to make every part of the OS acces­si­ble via the shell. And because of this we are now blessed with large array of “bina­ries”.

On Linux, on a typ­i­cal dis­tri­b­u­tion, you can have over 2000 bina­ries avail­able to you in the shell. Not all of them are usable in the com­mand line, but there are much more util­i­ties avail­able than on Win­dows. Pow­er­Shell bridges that gap by pro­vid­ing you cmdlets.

cmdlets are PowerShell’s com­mand line “bina­ries”. They are the object aware util­i­ties that you can use in the shell. Their name sets them apart from stan­dard bina­ries, that only use steams. With each new ver­sion of Win­dows and Pow­er­Shell, you get more and more of these cmdlets.

So the ecosys­tem on Win­dows is start­ing to thrive, there is no short­age of bina­ries you can exe­cute in your shell. But if you come from the Unix world, they will be com­pletely dif­fer­ent from what you are used to. Which makes using them a large learn­ing curve.

Unix in Windows

So is it pos­si­ble to have a good com­mand line expe­ri­ence in Win­dows. Def­i­nitely Yes! It may not be what you want, com­ing from Linux. But it is a leap for­ward, from what it was.

Ever so often, when I come back to Win­dows, I feel more and more like I’m on Linux. Mean­ing it’s start­ing to fit my work­flow, of doing every­thing from the key­board. Once you start using the shell you wont look back. I cer­tainly haven’t.

I’m curi­ous what other peo­ple have to say about the state of the Win­dows com­mand line. Please leave your thoughts and com­ments below.

Tomasz Bogdal

Engineer by day, hacker at night. I take the road less traveled, dissect the unknown. Give me something new, and I'll master it by the dusk of dawn.

One Comment:

  1. After read­ing this, I think I should finally bite that bul­let and give pow­er­shell a try. I’ve been a solid Ubuntu user for 4–5 years but recently bought Win10 to run in a VM to make sure my projects that com­pile on Linux would also com­pile on Win­dows. Installing MinGW was a slightly annoy­ing process but that pretty much does the job for me. Hav­ing said that, I don’t use the Win­dows VM for much sus­tained dev work, mainly for com­pil­ing and test­ing. It def­i­nitely isn’t as pleas­ant to use as the Linux native shell, for sure!

    One thing that makes me a bit reluc­tant about Pow­er­shell though is that it’s pre­sum­ably a dif­fer­ent shell lan­guage to the stan­dard Unix shell dialect sup­ported by Bash and friends. I know there’s already bash on Win­dows, but I won­der how dif­fer­ent to Bash powershell’s dialect is? The object-passing stuff does sound pretty neat, I’ve often found doing any com­plex pro­gram­ming in Bash to be a… *inter­est­ing* expe­ri­ence due to the absurd­ness of it as a script­ing lan­guage :D But it cer­tainly hits the spot as a shell.

    Btw, great to see some­one else who likes ter­mi­nals and archaic spellings of eng­lish words! We should coöper­ate together in an attempt to pop­u­larise these spellings! :D

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">