Thursday, December 21, 2006

Cygwin users: Get rid of the "Terminate batch job annoyance"!

Just figured this out and thought I would pass it along. If you find it useful, please send me your Christmas bonuses.

I am constantly using cygwin (and IMHO every Windows-oriented developer should be doing the same), but I find it rather annoying when I go to close it using Ctrl+D, Windows XP always asks me:

Terminate batch job (Y/N)?

Why? Because the mouth-breathing people who wrote Windows like annoying you. As a result, they decided that anytime someone ran a batch file, when the batch file was terminated early they would ask if you really meant to do that. Yes, you are stupid. You didn't really mean to hit Ctrl+C, but rather meant to send a letter to your Aunt Tilly using the Microsoft Vexation Paperclip (MVP), which can help you write that missive. It can do this for many other things too. Incessantly.

This results in my having to press Ctrl+C, clicking on the X in the window, or some other such irritant. I calculate that, with the extra time it takes to tell Windows to take a hike, I have spent approximately 2.6458 work hours during my time at my current employment. This is time that could have been spent doing more productive things, such as writing Unit Tests, emptying my Recycle bin (Oh, no, you really didn't want Windows to remove that, did you? Even though the system already asked you if you really Really REALLY wanted to remove it already? Oh, no, you are stoooooopid!), or send witty emails to my co-workers. So....

The solution is to start cygwin without using the cygwin.bat file. Here is what you do:

* Right-click on the cygwin icon/shortcut and select Properties in the popup menu. A dialog box should pop up. (If it doesn't, you are screwed. Go to Jail. Do not pass Go, do not collect $200.)

* In the Target entry field, put the following (instead of the call to cygwin.bat):

C:\cygwin\bin\bash.exe --login -i

(change the path to wherever you installed cygwin if you did it the non-standard way, you rebel scum).

* Click on OK to close the dialog.

* You will now note that when you click on your shortcut, your cygwin window will open as you are used to, but now Ctrl+D will immediately close the window!

Your welcome.

Make Visual Studio Your Java and JSP Editor!

Yes, you heard me right. I find that as a contractor I am constantly going from one editor to another. Each has their advantages, but when it comes to working on a Window's platform, I find that Visual Studio .NET gives me a lot and it is something I am comfortable with. I can write .NET apps, C++ applications, and C# programs, all within the same editor.

Recently, I needed to go back to editing some Java and JSP code. Although the final platform was to be a Linux flavor, the development environment was on Windows XP Professional. "Hey," I thought. "Why not use Visual Studio to edit my Java code?"

After a bit of research, here is what I came up with. The steps are three-fold:

  1. Find a way to fool Visual Studio into thinking that when it is editing a JSP file, it should treat it as if it were an ASP file. This would include syntax colorizing, tabs, auto formatting, etc., all according to the Options I've set in my editor.
  2. Find a way to fool Visual Studio into thinking that when it is editing a Java file, it should treat it as if it were an C++/C# file. Like above, this would use all the Options I've set in my editor.
  3. Find out how I can make Visual Studio recognize the key words in my documents so that it will colorize the correct syntax.
Here is what I did:

1. Enter some stuff into the registry. (A note for first-timers: Playing with the registry is dangerous stuff. Not as dangerous as playing with dynamite or kissing a redhead, but you get my drift. If you don't feel comfortable in the registry, call in a favor on a friend of yours who does and can handle the risk. The last thing I want is some whiny email regarding you doing something beyond your ability to handle. 'Nuff said.

    a. Click Start and then Run. Type in "regedit" as the program to open (or use your own favorite registry editor).

    b. Navigate to "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.1\Languages\File Extensions"

    c. Create a new key by right-clicking on "File Extensions" and selecting New | Key. Nave it ".java".

    d. Right click on the "(Default)" entry and choose Modify.

    e. In the Value data field, enter the following:
    {B2F072B0-ABC1-11D0-9D62-00C04FD9DFD9}
    Astute readers will note that this is the same Default entry you will find in the area under the ".cpp" extension.

Voila! Step number one is complete!


2.Step number two is similar, except this time we need to enter the .jsp extension with the .asp-like entry. Here's how:

    a. Click Start asnd then Run. Type in "regedit" as the program to open (or use your own favorite registry editor).

    b. Navigate to "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.1\Languages\File Extensions"

    c. Create a new key by right-clicking on "File Extensions" and selecting New | Key. Nave it ".jsp".

    d. Right click on the "(Default)" entry and choose Modify.

    e. In the Value data field, enter the following:
    {58E975A0-F8FE-11D2-A6AE-00104BCC7269}
    Again, you may note that this is the same Default entry you will find in the area under the ".asp" extension.


3. Fine and well. You now can edit .java and .jsp files in Visual Studio. But you may notice that the .java files will be colorizing some of the wrong words, and leaving other Java keywords alone. What gives? The problem here is that Visual Studio was designed to colorize C# and C++ keywords, so you are out of luck when it comes to Java keywords that don't match up to the C++/C# words. To solve this, we need to address step number three. Here goes:

    a. Create a file called "usertype.dat" and place it in your IDE directory. I installed with the default options and found mine at "C:\Program Files\Microsoft Visual Studio .NET 2003\Common7\IDE". Your results may differ.

    b. In this file, add all of the keywords for Java, separated by a hard-return after each. For example, here is mine:

     abstract
    boolean
    break
    byte
    case
    catch
    char
    class
    const
    continue
    default
    do
    double
    else
    extends
    false
    final
    finally
    float
    for
    goto
    if
    implements
    import
    instanceof
    int
    interface
    long
    native
    new
    null
    package
    private
    protected
    public
    return
    short
    static
    strictfp
    String
    super
    switch
    synchronized
    this
    throw
    throws
    transient
    true
    try
    void
    volatile
    while

    c. Save it and your done! Next time you open Visual Studio and load a .java file, you should see all of the Jva keywords colorized according to your preferences.


Did you appreciate this tip? Good, you can send me lots of money!

Seriously, I believe information is like manure; if you don't spread it around, it stinks. Work it back into the community, and all kinds of great things can grow.