2009-11-15

Making Windows a better place to be

Many developers including me are forced to use Windows at work due to various corporate reasons even when our work has nothing to do with Microsoft technologies. And we are all stuck with that terrible Command Prompt or a Power Shell which are crap compared to a proper terminal. However, there is a way to have a fully functional Unix terminal in Windows thanks to Cygwin and a patched version of Putty

I am doing this for several years and this is one of the first things I do in any Windows machine that I want to do some software development on, so it's time to come up with a little tutorial.

Setting up Cygwin and PuttyCyg

Getting Cygwin

Go to http://www.cygwin.com to download and run the setup.exe. Installation process is illustrated in screenshots below.
 


I suggest you installing cygwin directly to C:\cygwin as it's recommended. It's a significant part of your system and it is really worth the place in C:\ directly.



Cygwin offers "C:\Windows\System32" as a place for local packages, however I don't like that idea and keep it all under "C:\cygwin".


Some mirrors were failing for me with missing packages so I choose a respectable source and deal with slower download speed in exchange for reliability.



Choosing packages may take a while. You can go with default selection, however going through the long list is worth a while if you want to have goodies like vim, curl, ping, openssh, mc and so on.


Now go make yourself some coffee.


Don't add any icons or shortcuts because they open cygwin in that ugly command prompt we are about to get rid of.


Introducing Cygwin to your Windows

Now that you have the Cygwin, try it out by launching C:\cygwin\cygwin.bat. You will see something like this.


As you can see, a few files can be modified to configure your environment. Keep them in mind for future:
  • ~/.bashrc
  • ~/.bash_profile
  • ~/.inputrc

Now append these to the beginning of your Windows PATH environmental variable:

C:\cygwin\usr\local\bin;C:\cygwin\usr\bin;C:\cygwin\bin;



Run a fresh Command Prompt (if you are using Launchy or a similar program to run the cmd.exe, you have to restart it before the new PATH applies to programs you run.) and you will be able to do the following:


That's just a small benefit you get from cygwin, but it's handy to have unix commands anywhere in the system. If you think that cmd.exe is enough to enjoy unix commands, you are wrong. It fails to resize properly, it's hard to copy and paste. Compare using Putty with a remote machine to using Command Prompt on your local Windows box, It's like day and night.

Getting PuttyCyg

Get the latest puttycyg from http://code.google.com/p/puttycyg/. For the past year it's this one: http://puttycyg.googlecode.com/files/puttycyg-20090811.zip. You can put it in c:\cygwin\puttycyg to avoid a mixup with the original Putty if you use it.

Configuring PuttyCyg to access local cygwin

Create a shortcut to putty.exe from the puttycyg pack that you just extracted.


Run it to configure the local connection. Check "Cygterm" in Connection type and enter a minus (-) in Command.


Be sure to go to Window configuration and set Lines of scrollback to something more reasonable than the default 200.


Save the settings. Name the session "localhost".


Now click "Open" to test the configuration. You should see a working terminal.


You can now enhance the shortcut you created earlier to load the "localhost" session automatically. Just append "-load localhost" to the end of Target.


You're all set. A few resources to get you familiar with Cygwin:

4 comments:

  1. An alternative to puttycyg is Tera Term's cygterm+ from http://ttssh2.sourceforge.jp . I think PuTTY's terminal window is nicer though, if you don't need support for the various additional terminal types that Tera Term supports.

    ReplyDelete
  2. hey, Thanks for the post. I've been using puttycyg for awhile too and must admit it was the best thing to keep me from missing the Unix shell too much.

    ReplyDelete
  3. I rarely use the shell command anymore. too afraid to nuke my harddrive when I'm drunk typing.

    ReplyDelete
  4. Also, to fix vim behaviour, read the following:
    https://csc.cdf.toronto.edu/bb/YaBB.pl?num=1264722853/10

    ReplyDelete

Spam comments (i.e. ones that contain links to web development services) will be reported along with user profiles!

Note: only a member of this blog may post a comment.