Wednesday, April 08, 2009

The MS Windows CMD.EXE and Console 2

I like using Windows.  I have been on it for a long time now.  I have probably used every flavor since Windows 3.1.  It is very familiar and comfortable, I know how to do things and do them quickly and efficiently.  I have tried to switch to Macs a couple times, but I got frustrated because I knew that I should be able to do something, but I didn’t know how to accomplish it under OS X.
I am also a big fan of Linux.  I started off on Slackware loaded from CD’s, switched over to Redhat at 4.2 and now dabble with new releases of Ubuntu and Fedora.  I lot of the work I do professionally involves being very comfortable and proficient within a text based only Unix / Linux environment.  I have grown very accustomed to navigating around and getting things done from the command line.  As a matter of fact, in most circumstances I prefer it to a GUI.  If you ever see me at work, I am usually navigating my Windows machine via a Command Prompt.  Try this shortcut out for fun if you don’t believe how efficient it can be:
  1. Hold down the [Windows Key] and press R
  2. In the Open Dialog Box, type: cmd and press the [Enter] key
  3. In the Command Window at the prompt, type: cd %HOME%
  4. Now, type: start . and press the [Enter] key (that is start <space> <period>)
Now try this one:
  1. Go back to your Command Window
  2. Type: start c:\Progra    (don’t hit Enter yet)
  3. Press the [Tab] key – this is called “Command Completion”
  4. Your Command Prompt should now look like this: c:\>start "c:\Program Files"
  5. Now, press [Enter]
  6. Presto!  You should now be looking at Windows Explorer showing the contents of your “Program Files” directory
Yuck Horizontal and Vertical Scrollbars
So, that is why I like the efficiency of the Command Prompt.  Your fingers start to memorize what you want to do very quickly.  However, I have always been a little bit frustrated that the Microsoft Command Prompt did not have the ability to dynamically expand similar to a Unix X Windows Terminal.  You can set it’s dimensions, but once that is done, if you make the window smaller, the window starts getting horizontal and vertical scrollbars but doesn’t really change the number of rows and columns that are output.
Recently I came across a great program the solves this problem for me.  The name of the program is called Console.  I am currently using the beta version of Console 2.  It is hosted on SourceForge at http://console.sourceforge.net/.
Console does not replace or emulate the MS Command Window, it simply wraps it, however it allows you to dynamically resize your DOS window, both horizontally and vertically.  It also has the following features:Console with Transparency
  • Transparency setting for when it is focused and not focused
  • Tabs
  • Tab Renaming
  • Tab Profiles
  • Hotkeys
  • and many other customizations
One of the most useful things I have been able to accomplish with it so far has to do with its Tab Profiles.  I am a Java developer and used to code with Vim and Ant.  Some projects would require a certain classpath, others would require one version of Ant or a version of the Java JDK.  These are normally set globally in your windows profile.  For example, the command variable JAVA_HOME would be set to c:\java\jdk1.6.0.  When I program needed to know where the JAVA_HOME was, it was expecting that %JAVA_HOME% was available in my environment.  Based on our examples above, if in a Command Window, I type:
c:\>set JAVA_HOME=c:\opt\java\jdk1.6.0 
I could then type
c:\>cd %JAVA_HOME%
I will then be in the the directory: c:\opt\java\jdk1.6.0
I may also want to compile my java program by typing:
c:\>%JAVA_HOME%\bin\javac HelloWorld.java
The is a little easier than typing:
c:\>c:\opt\java\jdk1.6.0\bin\javac HelloWorld.java
Batch script for setting Env Variables
Java related programs always have expect these well known variables to be set.  For a single project  you may have to set JAVA_HOME, TOMCAT_HOME, CATALINA_HOME, M2_HOME, ANT_HOME, etc.
As I stated earlier what if each project required a different version of these?
What I have used in the past is create bat (batch) scripts that set my different environment variables, depending on the project I was working on.  I would start a Command Window and then run a batch script that will set all of these variables for me.
With Console, I can set up a custom tab using the Settings dialog box.  Within that, I can define a working directory, as well as the “Shell Command” I want to run.  Since Console simply wraps the CMD.EXE Command prompt provided by Windows, I set up the Tab to launch a CMD window, and then run my batch file within it.  That set me up with the exact environment I need for that session of programming.  When you define a custom tab, you also assign it a name.  Now here is where the icing goes onto the cake.  Command can be launched with parameters, that is, you can pass it additional information when you start it.  One of the switches allows you to tell Command which tab to open when it launches.  I could open a standards Windows Command prompt and type:
C:\opt\Console2\Console.exe -t "java devshell" Shortcuts Properties calling Console with Tabname
The –t instructs Console to open a custom tab, in this case “java devshell”.  Now remember, when I defined that custom tab, I actually told Console to run the script to set all of my custom environmental variables for me.
Console Shortcut calling Custom Tab I can then create a shortcut on my Windows desktop which calls Console with the exact command I would type at the Command prompt.  So I double click my shortcut icon and I am up and running!  I can create a shortcut for as many custom environments as I need.


The results of our labor.  Clicking on the shortcut shows Console running our custom environment:
Results of Clicking the Shortcut
Opening a second Custom Tab in Console:
Opening a second Custom Tab From within Console
The Output.  A Standard CMS window in Tab 1 and the java devshell in Tab 2.
Also, not the custom Java icon I was able to use on the tab.  This is selectable in the Tabs section of Console’s configuration.
 Results of Creating a Second Tab