11.11.2009

Pimping Cygwin part I: Terminal Goodness

My inaugural experience with Linux as a desktop started with Gentoo in 2005. I used openbox as my windows manager. The extent of my GUX (graphical user experience) was right clicking the desktop to launch a terminal and off I went. The concept of putting a file or folder on the desktop wasn't there and I became quite fond of mv, mkdir and rm. Since then I've tried to use RHEL, Fedora, Solaris, and all the 'buntu's. Aside of the fact my games don't run and the drivers were always substandard, I was never happy with the experience of the interface. The only thing I ever miss about Linux is the shell. A big argument in the developer community on switching to Apple is the use of a real bash shell. I guess that's if you consider Terminal to be a real terminal. In the interest of not losing potential followers, I'll refrain from speaking on why I hate Apple. I'd entertain some comment discussion for anyone who questions my right to hate them but that's not the point of this blog. Instead, I'm here help you configure Cygwin for some Linux goodness on your Windows machine. I'm calling this part one because it would be a tremendously long post to detail everything great about Cygwin. Ultimately it's a terminal/shell I'm after so let's start off with how to get that working.

The first real problem with Cygwin is that by default it starts up in a DOS window. Come on Windows! Is a command line that supports line wrap copy/paste really that hard to provide? This can be a really bad first impression to the casual user who installs Cygwin. Thankfully, there's an rxvt implementation available for Cygwin, but making that useful isn't super straightforward either.

First, you have to remember to select it during the install process. Otherwise, it is not included. Then what you need to do is modify the cygwin.bat file (or create a new one) and have it launch RXVT and bash instead of whatever crap it does by default. That is a simple one liner batch file.
C:\Cygwin\bin\rxvt.exe -e /usr/bin/bash --login -i

The next thing to do is to make it pretty. This is what I have in my .Xdefaults file which should be in your cygwin ~(that's home you linux newbie):
Rxvt*geometry: 120x40
Rxvt*background: #000020
Rxvt*foreground: #ffffbf
Rxvt*scrollBar: True
Rxvt*scrollBar_right: True
Rxvt*font: Lucida Console-12
Rxvt*SaveLines: 2000
Rxvt*loginShell: True
! VIM-like colors
Rxvt*color0: #000000
Rxvt*color1: #FFFFFF
Rxvt*color2: #00A800
Rxvt*color3: #FFFF00
Rxvt*color4: #6090F8
Rxvt*color5: #A800A8
Rxvt*color6: #00A8A8
Rxvt*color7: #D8D8D8
Rxvt*color8: #000000
Rxvt*color9: #FFFFFF
Rxvt*color10: #00A800
Rxvt*color11: #FFFF00
Rxvt*color12: #6090F8
Rxvt*color13: #A800A8
Rxvt*color14: #00A8A8
Rxvt*color15: #D8D8D8

Last, but far from least, is fixing some keys and disabling that hideous beep. That's all part of the file also located at ~/.inputrc. Here is what I use.
"\e[3~": delete-char

# VT
"\e[1~": beginning-of-line
"\e[4~": end-of-line

# kvt
"\e[H": beginning-of-line
"\e[F": end-of-line

# rxvt and konsole (i.e. the KDE-app...)
"\e[7~": beginning-of-line
"\e[8~": end-of-line

# VT220
"\eOH": beginning-of-line
"\eOF": end-of-line

"\C-v": paste-from-clipboard

set meta-flag on
set convert-meta off
set input-meta on
set output-meta on
set bell-style visible

I'm not sure if you need all of those. I've copied this .inputrc file around for a couple years now. The good thing is that it's a standard .inputrc file and you can Google through many many years of how to configure it to your liking. Same goes for the .Xdefaults.

The last real thing to fix is the prompt. The default one is not very good. For any Linux user this should be simple but for those in need, try adding this to your .bashrc file, located conveniently at ~/.bashrc:
export PS1="\[\e[36;1m\]\u\[\e[32;1m\]:\w > \[\e[0m\]"

So there you have it. Bash goodness in Windows. Go ahead. Tail that logfile. Pipe it to grep. Use a for loop with find and sed to rename some files. Enjoy the beauty of symlinks (and laugh at junctions while you're at it, what a joke).

Please comment if something doesn't work so I can update the post. This is only what I can recall from memory after having done this so many times. I'm thinking about covering X for Part II of the series. SSH + X-forwarding works quite beautifully.

Now if only I could get Keynote and Textmate to run in Windows. I'd be in heaven! I need the polyglot OS.