Thursday, September 17, 2009

A windows command shell that works, or a brief guide for *NIX users.

Some in the computing world actually have more experience using linux as a desktop than they do windows. Many others are at least very comfortable using the bash shell (or others) to navigate the file system, and frequently find it faster to move around using a shell than with a bunch of clicking.

Linux is the operating system of choice for many tasks here, but we're mostly using windows on the laptops. Windows is pretty damn good. All the pointing and clicking, however, is really damn annoying to terminal dwellers. Windows is the only thing out there that doesn't come with a shell from the later parts of the 20th century. The Mac has bash and fileutils, (not to mention a wealth of open source tools available). Windows is still stuck with a command interpreter from the dark ages just before the gods delivered color monitors, among other useful features. cmd.exe still seems to be the console from the last version of DOS that outsold windows. Ick. 

Powershell is something new, but we'll get there in another post.

To that end, here's what we do around here to make a windows machine more useful.  There's a number of projects out there that come into play, and most of them have been around for a while and are quite mature.

The first step is to install the cygwin project on the target machine.  Wander over there and grab the setup.exe.  Run it with adminstrator priviledges.  The cygwin installer itself is kind of cumbersome, but it gets the job done. Click through some stuff, select a mirror, and end up at the rather overwhelming listing of packages, reminding one of the package selection of Red Hat years ago.  No surprise there, as this program was started somewhere in the Red Hat community years ago.

Take heart, everything that's needed to make cygwin work is automatically selected.  For starters, most users will benefit from  grabbing rxvt and openssh.  The first delivers a traditional and largely compliant terminal emulator. It's a port of the venerable slightly improved xterm clone 'rxvt,' built to run under the native window management system. No X11 required.   The second delivers ssh and sshd, allowing remote access to and from the machine.  scp is in there too.

On this system rxvt-native is pinned to the start menu, and the taskbar.   It works not only for the open source toolkit, but also for using basic windows commands such as ipconfig, tasklist, taskkill, and shutdown.  If the windows commands are completely unfamiliar, use the /? switch to get help, similar to -h in most open source programs. 

It is possible to configure some of the rxvt behavior by editing the specific command parameters in the properties dialog of the start menu icon.  man rxvt for a comprehensive list of options. Of note are scrollback lines (-sl) scrollbar presence (+/-sb) and reverse video (+/-rv).

There's a decent number of command line utilities from the linux world ported to windows, both through the cygwin installer, and and as standalone binaries.  We use ffmpeg to do a lot of video re-encoding, and have discovered that programs symlinked into /bin (or /usr/bin, etc.) can be called from the command line.  ffmpeg and vlc go hand in hand in the encoding process this way.  More on encoding with open source tools on windows will likely follow our first video post.

Another useful discovery is that from anywhere in the filesystem, calling 'explorer .' will open up the Windows Explorer in the present directory.  Now if only we could figure out how to open rxvt to the current directory from a context menu in explorer.  Also, calling explorer on a file from the command line will open that file with the default windows application. Nice.

As an aside, instead of deleting that cygwin setup binary from the Downloads folder when you're done with it, move it to /bin using rxvt.  Run it as administrator as needed.  Look for packages there before scouring the web. It is also possible to cp all of the initial .* files for bash configuration over to your windows user directory, and replace your cygwin homedir with a symlink to your windows home, so that bash opens in your /Users/.... directory.

This by no means turns a windows machine into a free software compliant machine.  There are a  number of projects that supply unix like functionality, including genisoimage, ffmpeg, wodim, mencoder, and others, and the mingw project offers tools to bootstrap a basic compiling environment, but mileage varies. Some projects such as ffmpeg specifically support windows, but most don't, and really don't care if it builds for you or not.

Such is life. Simply being able to mv, cp, and ls the filesystem properly is very useful.

No comments:

Post a Comment