My windows setup is weird. Well, to be honest windows itself is a weird OS, but I make it even weirder by using Cygwin as my primary shell over there. This is not a perfect solution. In fact it is downright lousy considering that Cygwin (as wonderful as it is) is just a hackish attempt to port entire unix stack onto windows which doesn’t actually make it a good windows shell. It just gives you a unix shell that works on the platform but mostly just exists apart and besides windows and for better or worse is kind of a second class citizen.
If you are primarily a Windows user and not a filthy OS nomad like me, then using Cygwin is probably counter-productive. I’d highly recommend making Powershell your primary shell instead. Why? Because it is a first class citizen, and the proper admin tool for the OS. There is a great article somewhere by one of the engineers who developed Powershell which I never bookmarked – but trust me it exists somewhere. It touched upon the genesis of the project and how it grew out of the desire to have Unix like environment on the Microsoft platform.
You see, Unix shell is great. Everyone loves that environment, including Microsoft engineers. They liked it so much they actually made a valiant attempt to port a good chunk of the standard POSIX toolkit to Windows and they bundled them piecemeal in several Windows Server Resource Kits over time. Unfortunately they quickly realized that standard Unix tools are mostly geared towards editing and processing text files, because Unix keeps most of it’s configuration in plain text format. Porting these tools to windows doesn’t help administrators much, because they don’t deal with text files most of the time, but with weird constructs like the Registry. So while having a full POSIX compatible stack would be great, admins didn’t necessarily need it to do their job. What they needed was a shell that would give you the flexibility and robustness of unix command line environments (ie. not cmd.exe) but be able to juggle and manipulate windows internals as easily as unix tools manipulate text files. That’s how they built Powershel and that’s why you should be using it.
But to me it holds little of value because I primarily use Windows for gaming. If I do something serious on it, like programming for example, then I’d rather have it behave like unix. Which is what makes Cygwin a perfect tool for me. It allows me to use the same dot files and scripts across the board on all my machines.
Cygwin, being what it is, is not always perfect. A lot of tools I have on other platforms simply haven’t been ported to Cygwin environment and probably never will be. For example, Pandoc does not run under cygwin. It does however run under windows and you can actually call it from within the Cygwin bash shell as long as you are mindful of the paths (Cygwin does this thing where it has it’s own internal filesystem, and your Windows drives are mounted in /cygdrive durectory).
Another tool I use this way on windows is Git. When I first set it up on windows, I went with the MySysGit version rather than the Cygwin one. My reasoning was that I wanted it available natively in the OS to tools that may want to use it. When I later installed it natively in Cygwin I noticed that having two slightly different versions of Git on your system doesn’t work very well. So I decided to keep the native Windows version and just call it a day.
I use MinTTY as my primary terminal, and I noticed that whenever I called git from it I didn’t have nice colorized output I’m used to. This is mostly a MinTTY issue because it was primarily designed to be a unix shell running on Windows and as such it supports the ANSI escape codes but not Windows escape codes.
The easy solution to this problem is to switch to the default Cygwin shell which is essentially the standard windows terminal with a back-hack that lets it render the unix ANSI color-codes. But I refuse to do that because that terminal blows. I searched long and hard for a MinTTY centric solution but it appears that while a number of people complain about it, the developers are not particularly interested in fixing it because it is hard, and since they personally never call native Windows apps from within MinTTY then it is not a real problem. Because that’s the way we do things in the open source community folks. Oh, you have problem that doesn’t actually affect me? Fuck you then. How about you write a patch and maybe I’ll consider merging it in. Actually I’ll probably just delete it but who knows.
Eventually I realized that if I actually want to have color in my Unix shell, I need a different terminal and I eventually stumbled upon ConEmu which is rather aggressively developed, all purpose Windows terminal. By all-purpose I mean it can actually work amazingly well as a Powershell terminal. By default it wraps itself around cmd.exe and gives you slightly less shitty command line experience. It supports tabbed interface, transparencies and has a nifty status line.
If you want to run Cygwin inside of it, all you need to do is to create a shortcut (or a script) that will call it like this:
C:\ConEmu\ConEmu64.exe /cmd "C:\cygwin\bin\bash.exe" --login -i
Obviously, you may need to adjust the paths a bit. I installed both Cygwin and ConEmu in the root directory on my c: drive because c:\Program Files (x86) is the worst path in the universe, and whoever decided that a crucial system path needs two spaces and two non-alphanumeric characters in it needs to be slapped upside the head with a hedgehog.
Since the ConEmu developer envisioned the terminal as a multi-purpose tool, the ANSI color code support is baked in. This means that everything just works as it should without having to do anything:
Hell, the default UI even comes with Solarized theme presets you can enable from the Settings menu. This was rather surprising to me, because very few Windows centric tools know or care about the Solarized project. In fact, quality of a windows tool aimed at developers can be almost solely judged by the degree to which it supports these themes. If it ships out of the box with default solarized theme, it means serious business – download and/or buy it immediately. If it has it as an option, it’s probably pretty good. If it’s missing… Well, as long as you can use custom themes it might still be OK, but it will probably suck.
ConEmu has 3 versions of the dark theme, and two of the light theme and they are all off in various ways. I know this because I’m a Solarized junky and I install it on everything and I write my scripts to output colors in such a way that it looks good in these themes. All of the included themes got the overall look right, but then failed at rendering certain colors (especially red and green and pink/purple) which are integral parts of my bash prompt. So I had to tweak it a bit:
You can compare it to the default color setup to see the changes I made. I think it is still slightly off, but at this point it doesn’t bother me anymore. Still, the creator gets points for trying. While the implementation wasn’t perfect, it was close enough that it took only a few seconds to fix.
The only real gripe I have with ConEmu is that it’s color palette is rather limited and it doesn’t let me do things like run Vim with Solarized Light theme while coloring itself according to Solarized Dark. MinTTY handles this sort of thing swimingly and without complaining. That said, when I’m working on Windows I typically use Gvim rather than the console vim so this is less of a problem than just a minor nuisance. Besides, if I do want to use Console vim, I can always fell back on MinTTY and just deal with the lack of color in git output.
I’m not actually sure if this post will be useful for anyone who isn’t me, because like I said – I’m a bit of a weirdo when it comes to my windows shell environment. I like it to work and feel the same way as my unix and mac environment. What do you guys use? Do you run Cygwin on windows? What terminal do you use? How about Powershell? Let me know in the comments.