Sunday, January 21, 2007

Soup up Microsoft's Command Shell

Recently, I've gotten back into programming. Its been a couple of years and the last time I was into it I was working in a UNIX environment. Now I'm in a Window's XP environment. I've already felt a bit frustrated with Microsoft's standard command shell (cmd.exe). First, it lacks many of the commands I have come to know and love. Second, it's tab auto completion is lacking - when you hit tab, it cycles through all the filename matches rather than displaying a list of all of the matches. And third, I want my command shell to preserve my command history across sessions. I've been searching around, and I've yet to find a free command shell in windows that has all of these features. Here is what I found:

cmd.exe: This is the standard command shell. Its not to difficult to get it to use windows ports of the UNIX commands I want with the help of unxutils. Here and here are useful instructions for setting this up.

Winone: This is the closest thing I've seen to what I want. In fact, it is exactly what I want - but there is no way I'm going to pay for a decent shell.

Powershell: The second closest. It definitely a leap in the right direction. Its even possible to get it to store the command history. I found instructions to do this here and here, but unfortunately, they are a bit outdated (and its sort of a pain). In order to get this to work, here are the steps I took. After installing Powershell, type "powershell" in the Start->Run menu. Type "$profile" (with the $). This tells you where your profile file is located. Mine is located 'My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1'. I needed to create the WindowsPowershell directory and use a text editor to create Microsoft.PowerShell_profile.ps1. When I restarted PowerShell, it gave me a message to the effect that the "execution of scripts is disabled". In order to fix this, type into PowerShell: "set-executionpolicy RemoteSigned". Then you can paste the following (slightly modified) code in the Microsoft.PowerShell_profile.ps1 file:

$MaximumHistoryCount = 10000
function bye
{ Get-History -Count $MaximumHistoryCount |Export-csv ~\history.csv

if (Test-path ~\history.csv)
{ Import-csv ~\history.csv |Add-History

Ok - so now I can view my history, but I want to be able to USE IT. This is seeming like its hardly worth it.

That said, this is probably the future of the command shell in windows - and so its probably not a bad idea to start getting acquainted with it now. Here is a good quick start guide.

Win-bash: Major problem - doesn't seem to implement tab completion at all!

Cygwin: Still no automatic saving of command history across sessions. Uff!

GnuWin32: In order to install it, run download.bat (it will take a while) to download everything and then run the install.bat (again, this will take a while). Follow the directions (again, again, it will take a while). Now that I've spent all this time setting it up, it doesn't remember my command history between settings.

Now I'm just f-ing depressed about this.

UPDATE: I have found what I want. IPython has it all.

No comments: