Open in TextMate

Open in TextMate allows you to open the current folder or selection from Finder as a TextMate project. There are a few scripts for this, but this one is the latest iteration and it comes with a nice icon that fits will into the Finder tool bar.

Open in TextMate tool bar item

Henrik also provides tool bar items for Open in Terminal and Glob Select which are definitely also worth checking out!

And for the records, this is not related to “Edit in TextMate

11 Comments

  1. 29 Oct 2007 | # Josh Walsh wrote…

    This is great, really useful.

  2. 01 Nov 2007 | # Denny wrote…

    It goes even easier: just drag the TextMate icon from the "Applications" folder to the finder titlebar.

  3. 01 Nov 2007 | # Rachel Greenham wrote…

    For people who like like living in the commandline, I thought I'd share a couple of little scripts I made for working in projects (eg: websites, source trees…) They just want to sit in your $PATH somewhere and be made executable:

    the first: tm

    #/bin/bash
    # tm <pattern>...
    # Open all files under this location with the
    # given (wildcarded) name(s).
    # eg: tm \*Servlet.java
    
    for i; do
        if [ -f "$i" ] ; then
            mate "$i"
        else
            find . -path './{arch}' -prune -o -name "$i" -print | xargs mate
        fi
    done
    

    And the second: tmgrep

    #/bin/bash
    # tmgrep <text> <pattern>...
    # Open all files matching the given pattern(s)
    # under this location that contain
    # the given text.
    # eg: tmgrep "extends SomeClass" \*.java
    
    for i; do
        if [ -z "$GREP" ] ; then
    GREP="$i"
    else
        find . -path './{arch}' -prune -o -name "$i" -print | xargs grep -l "$GREP" | xargs mate
    fi
    done
    

    You can call them what you like; On my system I still call them xcode and xcgrep because the original of these scripts opened files in XCode rather than TextMate and that's what my fingers are used to typing now. (I also have a variant that opens in gedit under Linux, also called xcode and xcgrep.) But textmate is way nicer for doing this stuff especially as, when you use the above and it matches a bunch of windows, they all turn up in a sidebar in one new window, rather than covering your desktop in windows… which can get especially tiresome when you accidentally tell it to open a couple of thousand files…

    Obvious and probably easy enhancements might include:

    • allow regexp expressions (optionally) in tmgrep. I didn't especially miss it myself as regexp has never quite become second-nature.
    • be more generic in what application it uses to open the files. On OS X of course, you could actually just replace mate with open as long as you've already configured the system to open the files in the right application. The grepping variant obviously is unlikely to be very useful on anything other than text files.
    • cope with folders and filenames with spaces in them. I think I know how, I just haven't needed it enough to make it happen and get it all tested.

    The -path './{arch}' -prune bit is just because we use bazaar for our source control and I don't want this command picking up the files of the same name inside its working directories. You can lose it if you want; I've left it in as an example.

  4. 01 Nov 2007 | # Allan Odgaard wrote…

    Rachel: As for spaces in filenames, use -print0 instead of -print and then give -0 to xargs (this makes the printed names be null-terminated, and likewise has xargs expect them to be that).

    And for naming it xcgrep, I need to put the following on all my servers to avoid having my sessions littered with command not found :)

    alias mate='nano -w'
    
  5. 01 Nov 2007 | # Rachel Greenham wrote…

    I know about -print0 and xargs -0. :-) The part I wasn't sure about whether it would work is the tmgrep one where we pipe through xargs twice, and I'd just taken some headache pills when it occurred to me and didn't feel like testing it out. :-) In all the time I've used these scripts I've not found myself needing to use them where it's a problem, or it would have been fixed.

    find . -name "$i" -print0 | xargs -0 grep -lZ "$GREP" | xargs -0 mate

    I think that would work, but wasn't really sure there might not be some wonky edge cases.

  6. 02 Nov 2007 | # Allan Odgaard wrote…

    That should work, also find can be made to execute the grep like this:

    find . -name "$i" -exec grep -sq "$GREP" '{}' \; -print0 | xargs -0 mate
    

    I also suggest this addition to the script:

    echo -n "$GREP"|pbcopy -pboard find
    

    Then when the file(s) open, one can use ⌘E to jump to the match :)

  7. 14 Nov 2007 | # Darryl Zurn wrote…

    This is very close to what I want to do. I already have a command bound in TextMate that will take whatever text is selected and open either or both files with these filenames:

    open "file://path/to/$TM_SELECTED_TEXT.pdf" open "file://path/to/$TM_SELECTED_TEXT%20No%20PDF"

    What I want is to open any and all files in this directory that starts with $TM_SELECTED_TEXT.

    And there are spaces in the filename but not the path.

    Any help is appreciated! Thanks Darryl

  8. 15 Nov 2007 | # Allan Odgaard wrote…

    Darryl: The context is not entirely clear here, but simply using an unquoted * in the file to open should work for “completion”, for example:

    DIR=/tmp
    EXT=.php
    mate "$DIR/"*"$EXT"
    

    That will open all files with extension EXT (.php) in the DIR folder (/tmp). And both DIR and EXT can contain spaces.

  9. 12 Dec 2007 | # Dustin Schau wrote…

    Hey, cool idea!

    Here's a little something I whipped up…fits a little better with OS X toolbar.

    http://www.dustinschau.com/Downloads/TextMate.png

  10. 11 Jun 2009 | # Open in Textmate « Sketch Blog wrote…

    [...] helpful, since I don't have TM set as my default editor for HTML and CSS files.Check out the full post, as well as this other that talks about customizing the icon for the script. [...]

  11. 02 Oct 2009 | # Configurer Textmate pour le développement web (html-css-php-javascript) « washaweb wrote…

    [...] Open in Textmate Copiez cette petite extension n'importe où sur votre Mac, puis clic-droit dans la barre d'outil d'une fenêtre du Finder (dans la partie avec les petites icônes) et "Personnaliser la barre d'outils…". Faites glisser l'extension dans la barre et cliquez sur "Terminé". [...]

Comments closed, you can use the mailing list for discussion.