A Unix Guy looks at Powershell

I have to admit that I’ve always been skeptical of Windows and its command-line. After learning the Unix shell years ago, I hated using cmd for anything. Way too limiting.

I remember when Powershell came out and I gave it an initial try — but lots of software I used started up with.bat files and at that time Powershell didn’t run them. At. All. So I left Powershell behind.

But I was still stuck on Windows and I was thankful for Cygwin. It’s not perfect — not even close — but I had the power of the Unix command line on Windows. My biggest gripe with Cygwin has always been that it’s slow. That’s because Windows doesn’t have fork(), which is basic Unix functionality. So Cygwin had to emulate it and it’s quite slow. Here is a good discussion on that performance hit on StackOverflow

For me, this performance hit is most prevalent when using git-svn. When it’s syncing your git repo to the online Subversion one, it’s not a trivial feat and on Cygwin can take a while. I had been lamenting this fact and trying to figure out what to do about it.

In the midst of this I went to a conference that had a few talks on Powershell. I decided to go to one to see how things had changed. I wasn’t going in with much hope. This session was taught by Joel Kauffman and he did a good job going over basics and said, very matter-of-factly, “It can run batch files,” and showed us examples. I know that it didn’t used to, but now they obviously work. And what he showed me is that it could do everything that I generally did from my Unix prompt. But could I get git-svn working?

When I got back I did a little digging and found out that GitHub for Windows included a Powershell config. I didn’t care about the GitHub client, per se, but I did want the git cli environment.

I installed it and fired up the prompt. Not only did git work just fine, but git-svn was included with it! After a couple of syncs I found that it was quite a bit faster than the same commands in Cygwin. My next surprise is that my favorite Unix commands worked out of the box — grep did a text search on a file, ls listed the current directory (though not many arguments worked, like -l). I even used / instead of \ when moving around my drive and Powershell either accepted them or changed them to \. I thought that I could get used to this.

Using my notes from Kauffman’s talk, searching the web, and looking at the config from GitHub’s prompt, I came up with this profile that gives me an even better Unix-like configuration.

In the midst of my configuration I discovered PsGet which is a package manager for Powershell modules which makes them easy to install. The PsGet package I can’t live without is PsReadline that gives Powershell the same functionality as Bash or Zsh — including Ctrl-r which has become habitual to me. And gvm has been ported to Powershell which you can install via PsGet. That helps me with all my Grails/Groovy/Gradle needs.

It’s not all roses — the Windows version of Ruby flatly refuses to do fork() so the git-smart plugin I use doesn’t do merges, so I still have my Cygwin prompt for that. So I keep both… and am more productive because of it.

One thought on “A Unix Guy looks at Powershell

  1. Ben says:

    With the prevalence of high-quality virtualization tools such as VirtualBox, why suffer through the annoyances of cygwin or powershell when you can bring up a whole BSD or Ubuntu (or whatever Linux you want) instance and run the all the scripts and tools from inside the real OS?

    1. Hey Ben,

      My current spot has me with a machine with no admin rights — in fact, if I install anything that brushes against the Windows registry is denied execution. Even getting Cygwin initially installed was problematic. In that environment, you can’t install VirtualBox (not even PortableVirtualBox — I tried both). That is my ultimate configuration but, alas, I can’t. I think Powershell is a good comprise in such corporate environments.

Leave a Reply

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