In the last couple of posts, I have been mentioning different command line tools that I've been using (specifically Nant and SchemaSpy). While some people love command line applications and using the command prompt, there are some that cherish the nice Windows GUI and the mouse. The issue with the GUI is that applications like Nant and SchemaSpy don't really work well out of the box if you double click on them. This means that in order to have double click functionality that does something, you will need to script it out using tools like shell or PowerShell scripting that executes the configured command for the desired results. If you don't create (and subsequently debug) the script wrapper, you will find yourself opening up the command prompt, navigating to the directory, and then typing in the command manually. Thankfully, there's a tool out there that makes things easier.
The Command Prompt Explorer Bar
The Command Prompt Explorer Bar is an open source tool on the Code Project web site developed by Pavel Zolnikov that allows you to place a command prompt window inside of your windows explorer window (see image below). While this immediately doesn't sound useful, it offers some powerful productivity features that a typical command window doesn't. First, when you open the Command Prompt Explorer Bar, it immediately takes you to the directory you're in. So, if you are in the directory that contains the Nant script you want to manually execute, you can open the command prompt and immediately type in your command. In addition, as you move around windows in the explorer window, your command prompt automatically synchronizes with it. Last but not least, the Command Prompt Explorer Bar offers the ability to have macros.
Figure 1: The Command Prompt Explorer Bar for a user's (named llama in this case) home folder.
Where to Download the Command Prompt Explorer Bar
As stated previously, the Command Prompt Explorer Bar is an open source tool on the Code Project web site. You can download the installation binaries and/or the source code from this location. After you have downloaded the installer for it, you will be able to begin using it.
How Do I Open it?
The Command Prompt Explorer Bar is very simple to use since it's just an embedded command prompt at it's core. It works in both XP and Vista and there's no special window style needed to have it open (folder bar is supported as is Vista's Aero interface). There are two ways to open the Command Prompt Explorer Bar. First, you can go to the View Menu > Explorer Bar > Command Prompt menu option. The second way is to just press Ctrl+M in the folder. NOTE: Ctrl+M does not work if you are literally on your windows desktop, a file system/explorer window must be open for the Command Prompt Explorer Bar to open.
What Are Those Icons For?
As you may have noticed from the above image or if you've installed the Command Prompt Explorer Bar already, there are a series of buttons/icons on the left sidebar. These buttons help provide some quick additional functionality. Going from top to bottom, the buttons are as follows:
- Command Menu - Provides the command prompt context menu, similar to right clicking inside of the prompt. Clicking directly on the button shows an "About" dialog.
- Synchronize - Turns on and off the ability for the command prompt to synchronize as you move through folders above it.
- CLS - Sends the CLS command to the command prompt; clearing the screen.
- Get Selected Folder Items - Enters all items you have selected in the folder view above in a <space> separated list.
- Enter Key - For those who don't like to press the enter key on the keyboard...I think.
- Esc Key - Used to clear a partially typed line; same as the Escape Key on the keyboard.
- Macro - A drop down menu containing a list commands that you can use for quick access. (more on this in the next section)
- Grow - Grows the constraints of the Command Prompt Explorer Bar.
- Shrink - Shrinks the constraints of the Command Prompt Explorer Bar.
Using Macros
When the Command Prompt Explorer Bar was created, Pavel Zolnikov entered in the ability to create and use macros. The macros that he supplied with it were very much .Net Command Prompt tools. Browsing the list, you'll find a number of macros for generating a type library, register a COM compliant assembly, and registering an assembly in the GAC. There are also some macros for traditional command prompt commands like attrib and cd. There is also a few macros that contain a {1} in their name. What this syntax represents is the first selected item in folder list above. For example, if you highlight a folder and then call the "cd {1}" macro, it executes the change directory command into the selected folder in the command prompt. It does not sync back to the folder view however.
Adding New Macros
While the default macros are useful, Pavel also provided us the ability to create our own macros. This is where it shines. To create a new macro, Click on the Macro menu button directly. This will open the C:\Program Files\Command Prompt Explorer Bar\macro.xml file. Inside of this file you'll see some very basic XML syntax which is described below.
- <group> - The document element as well as elements that denote a grouping/submenu list of macros
- text - Sets the text to be shown as the submenu item.
- <macro> - Denotes a macro-ed command.
- text - Sets the menu text to be shown for the macro
- execute - a boolean value telling the command prompt to execute the macro when selected or not.
- command - the command the macro will execute upon selected if different than the text.(optional)
- {0} - types out all currently selected files in the folder view
- {1} - types out the first selected file in the folder view (subsequent numbers represent that element of selected items; i.e. {2} is the 2nd selected item).
- {1:n'} - types out the last selected file in the folder view (n' represents the inverse order of the files selected)
Now that we've looked at the syntax, let's add a new macro group with a Nant command. This will assume that you have Nant installed and configured with the Nant.bat file in your system path as described by the Nant installation and configuration steps.
1: <group text="Nant">
2: <macro text="completeBuild {1}"
3: execute="true"
4: command="Nant -buildfile:{1} completeBuild" />
5: </group>
Adding this snippet to the file (inside of the parent <group> xml document element), the new macro group and command is instantly added to the macro menu (no close and reopen needed). This command allows us to select our build file in the folder view and then executes the macro to call it's "completeBuild" task that it presumably contains. Quick and easy for executing command line tools and applications without having to navigate and type in the command in a command prompt nor mess with scripted wrappers.
In Summary
While this tool isn't the most amazing one out there, it is very useful if you find yourself working in a command prompt a lot. Great tools and utilities like Nant and SchemaSpy can be easily reduced to a simple click of a macro while you never have to leave the window you are browsing the file system with.