April 13th, 2007

launching textpad from cygwin

This is a simple bash function that I use pretty often. It comes in handy when I’m navigating a tree of source code in a cygwin bash shell, and want to edit a file in TextPad. You can just put this line in your .bashrc file, and make sure the directory where TextPad.exe lives is in your $PATH environment variable:

function tp() { textpad $(cygpath --mixed $1) & }

This allows me to do things like:

$find . -name '*Foo*.java'

which returns results like:

./src/com/spugbrap/foo/bar/TestFooImpl.java
./servlet/com/spugbrap/baz/FooDispatcher.java

Then I can just copy one of those full (but relative) paths to the clipboard, and paste it into a command that looks like this:

$tp ./servlet/com/spugbrap/baz/FooDispatcher.java

Now, regardless of where the root of this relative path exists on the file system, it will open that file in TextPad.

The only limitation that I run into with this is that it only lets you specify one file to open. It could probably be modified to handle multiple files pretty easily, but this hasn’t bothered me enough to deal with yet.

7 Responses to “launching textpad from cygwin”

  1. ClintJCL Says:

    EditPlus!

  2. spugbrap Says:

    TextPad!

  3. ClintJCL Says:

    Hmm… I’ve never done a side-by-side comparison.. I just know textpad didn’t stick with me, and editplus did. but some of that may have been timing — 1999(?) vs 2005.

  4. spugbrap Says:

    Woohoo! Thanks to Bruce, who posted this for loop in a comment on Marc Abramowitz’s blog, I now have a ‘tp’ function that supports multiple paths on the command-line:

    function tp()
    {
    for ((at=1; at < = $#; at++))
    do
    p="$p `cygpath -wa ${!at}`"
    done
    textpad $p &
    }

  5. ClintJCL Says:

    for your bunghole?

  6. spugbrap Says:

    are you threatening me?

  7. spugbrap Says:

    Ack! The function I posted in the comment, above, had a flaw: the ‘p’ variable never gets reset. Every time the ‘tp’ function is executed, the string ‘p’ already contains the values from every previous invocation, because the function keeps appending to p, without ever clearing it.

    The following works better, and includes debug output that I don’t mind seeing every time I run the function:

    function tp()
    {
    echo tp:input:$*
    unset p
    for ((at=1; at < = $#; at++))
    do
    p="$p `cygpath -wa ${!at}`"
    done
    echo tp:output:$p
    textpad $p &
    }

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>