Wednesday, 17 December 2008

Cygwin, Emacs, Unix on Windows

My new work-place is pretty much a windows-only shop, but I miss having a nice command-line, Perl and emacs to hand.
Though I could get most these things separately I've installed Cygwin and it's quite Joe-Lush. Just run the set-up from the website. Probably best to install some extra packages rather than just the basics; I went for:
  • emacs (for editing)
  • emacs-X11
  • nano (for basic editing)
  • perl (for everything)
  • xclock (for testing X)
If you can bear it, install in C:/cygwin as suggested, it makes things easier. Probably a good idea to copy the setup.exe to the same folder afterwards since you'll be wanting to install more packages at some point, and for this you need setup.exe.

X-server

A few things need tweaking out of the box. Firstly an X-server. If you want to use graphical apps you'll need one of these. Cygwin does come with an X-server but I always found it a bit fiddly; try Xming, it's ace. You need to install it and start it running. It won't do anything much itself, it'll just sit there in the background waiting to display any X applications.

Home Directory

Under Windows XP your default home dir will probably be in the "Documents and Settings" folder. Spaces in your home dir path will most likely cause problems, so change it. Start up cygwin, and create yourself a home directory (e.g. mkdir /home/justin), then edit your /etc/passwd file - you should be able to work out which part of the line to edit for your user (probably the last one), but be careful, if you screw this up there's no easy way to fix it. I'd suggest using the nano editor:
nano /etc/passwd

Setting DISPLAY

To use X you'll need to set your DISPLAY environment variable. Do it from the the command line:
export DISPLAY=localhost:0
It's probably easier to create a .bashrc file in your home dir and add this line to it. Which leads us to...

BASHRC

For some reason your .bashrc might not get read on start-up. Fix this by adding:
. ${HOME}/.bashrc
to your /etc/profile file (note the dot at the start of that line).

Terminal & Putty-for-Cygwin

The terminal emulator that comes with Cygwin is not that great; resizing is nasty, copying and pasting is worse. I use Putty when SSHing around from Windows and it turns out someone has patched Putty to work with Cygwin, god bless them. Take a look at PuttyCyg - download it and copy the 3 or 4 files in the zip file to C:/cygwin/puttycyg for example. Then run puttycyg and save a cygwin session or run directly by creating a Windows short-cut, and within properties set the Target to
C:\cygwin\puttycyg\putty.exe -cygterm -
Perfect.

Fonts

Finally you'll obviously be wanting to use 6x13 as your font, the acknowledged King of Fonts. Get it for Windows from http://www.ank.com.ar/fonts.

No comments: