I do a lot of development on Windows (I love Visual Studio), but I try to spend most of my time on Linux, because I love the usability of the Gnome desktop and the power of its development and CLI tools. So I’ve gotten into this habit of trying to make my Windows XP machine act much like my Linux/Gnome desktop. How am I doing that? So far, it includes getting a unix shell and associated programs running in Windows, and emulating the awesome hotkey and window management I get with Gnome and Metacity. I’ll write a series of posts on how to get this stuff set up.
First is Cygwin. Cygwin is a drop in unix shell environment (it supports X libraries too) which allows you to run unix binaries built for Cygwin and use the wonderful command shells, like bash, in Windows. Cygwin is here and is fairly easy to get going, if you can wade through the blindingly frustrating usability nightmare that is their setup.exe
These are useful apps I always forget to select in setup.exe, as they’re not selected by default, so if you need them, check them off:
nano
openssh
subversion
cvs
rxvt
The real challenge is getting a usable terminal emulator to run Cygwin programs in. Cygwin, by default, opens cmd.exe, which is the Windows command prompt. command.exe is notorious for being quite possibly the worst terminal emulator ever developed. To this day it’s still styled like a Windows 95 window, because it’s skinned using some arcane pre-GDI (?) window border. You have to bring up a dialog box to resize it horizontally, it will not accept most control key combinations and the cutting and pasting leaves much to be desired.
Thankfully it’s easy to replace. You can use the terminal that comes with putty modified for use with Cygwin, or you can use rxvt, which is what I use. rxvt can be installed through Cygwin’s setup.exe, and will be installed to C:\cygwin\bin\rxvt.exe
rxvt is not a pretty program, but it works adequately. The first order of business is to get it to launch your Cygwin environment and to start in your home directory.
In Cygwin, I have my home directory set up as c:\documents and settings\reformist, which is also my home directory for Windows (%userpath%). It makes things easier having them be both the same directory. To do this, while in Cygwin, I symlinked /home/reformist to /cygdrive/c/documents and settings/reformist
With that setup, you can fire up a cygwin environment with rxvt using this command:
C:\cygwin\bin\rxvt.exe -e c:\cygwin\bin\bash.exe --rcfile "~/.bashrc"
Notice I start the bash shell, and I also tell bash to look for my rc file in my home directory. Here’s the contents of my .bashrc for windows:
cd ~
export INPUTRC=$HOME/.inputrc
export EDITOR=nano
PS1='[u|W]$'
PATH=/usr/bin:$PATH
What’s up with that PATH variable? On some of my Windows installs Cygwin (or bash, or rxvt) won’t include /usr/bin in the path, so I add it manually. Strange, I know.
The other thing of note is the INPUTRC line. This is used to ensure that rxvt picks up my home and end keys correctly and does the right thing with them. Here is the .inputrc file I use for rxvt, which resides in my home directory (%userpath%):
# Home Key
"e[7~":beginning-of-line
# End Key
"e[8~":end-of-line
# Delete Key
"e[3~":delete-char
# Insert Key
"e[2~":paste-from-clipboard
The next order of business is to change the assinine default of rxvt to put its scrollbar on the LEFT side of the window, and instead make it show on the right. I also like to change a few display properties, like the title rxvt shows. You can do all of this by putting a .Xdefaults file in your home directory. Here’s mine:
rxvt*title: Bash
rxvt*foreground: black
rxvt*scrollBar_right: true
rxvt*colorBD: 1
rxvt*font: courier
rxvt*saveLines: 10000
rxvt.backspacekey: ^?
And with that, you should have the unix CLI tools at your disposal, usable through an adequate terminal emulator.
References:
Cygwin Bash Shell