Monthly Archives: December 2008

Use Terminal to Find and Create a Textmate Project

I’ve been spending more time than usual using the Terminal, and I like how quick it to get around the file system. Today, while messing with the linux find command, I started to wonder if I could search for a folder, and then open it as a project in TextMate, all with a one line command. Turns out you can!

In the following example, my current location is my Desktop, and I’m looking for a newsletter folder called “goodie69.” Assuming it’s found, open it in TextMate:

[ ~/Desktop ]$ find . -type d -name 'goodie69' -exec mate {} \;

Note that you need the TextMate command line tool installed and in your path to do this.

So, first I’m issuing the find command, the single dot specifies start in the directory I’m currently in, the “-type d” means I’m only looking for directory names, and then I’m taking the results and executing the “mate” command. You need to close out the exec command with the brackets, backslash and semi-colon.

If you use BBEdit, and have the bbedit command line tool installed, you can replace “mate” with “bbedit”.

You can also specify any directory to start looking in (by default, this command will look in subdirectories). For example, if you have a folder called “clients” inside your home folder, and want to look in there for a particular folder, you can do something like this:

[ ~/Desktop ]$ find ~/clients -type d -name 'goodie69' -exec mate {} \;

And if you want to search for a file and open it in TextMate:

[ ~/Desktop ]$ find ~/clients -type f -name 'i-like-muffins.txt' -exec mate {} \;

Or,  you can just use Quicksilver ;)

To do this in Quicksilver – you just start typing the name of the folder, then tab over and select “open with” as the next option (or just start typing “with”), then tab over start typing “TextMate” until TextMate shows up. Then Enter. Whamo. If you don’t see the “open with” option, refer to the article above.