28 October 2007 — Posted by Allan Odgaard
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.
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”
29 Oct 2007 | # Josh Walsh wrote…
This is great, really useful.
01 Nov 2007 | # Denny wrote…
It goes even easier: just drag the TextMate icon from the “Applications” folder to the finder titlebar.
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
$PATHsomewhere and be made executable:the first:
tmtm <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:
tmgreptmgrep <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
xcodeandxcgrepbecause 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 calledxcodeandxcgrep.) 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:
matewithopenas 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.The
-path './{arch}' -prunebit is just because we usebazaarfor 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.01 Nov 2007 | # Allan Odgaard wrote…
Rachel: As for spaces in filenames, use
-print0instead of-printand then give-0toxargs(this makes the printed names be null-terminated, and likewise hasxargsexpect 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 withcommand not found:)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 mateI think that would work, but wasn’t really sure there might not be some wonky edge cases.
02 Nov 2007 | # Allan Odgaard wrote…
That should work, also
findcan be made to execute thegreplike this:I also suggest this addition to the script:
Then when the file(s) open, one can use ⌘E to jump to the match :)
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
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:That will open all files with extension
EXT(.php) in theDIRfolder (/tmp). And bothDIRandEXTcan contain spaces.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