Apparently this question is quite common – since TextMate does not show the full path of the currently edited file, people are not entirely clear on the file’s location. So I was asked to do this tip, which will cover 4 different methods of discovering the path to your current file, and hopefully teach some new tricks too.
Tab Tool Tip
The simplest way is just to hover the mouse cursor over the relevant tab, and you’ll get a tool tip showing the full path to the file.
Reveal in Project
At any time while editing a file in a project you can press
⌃⌘R (or File → Reveal in Project) to select and reveal the file in the project tree. This is handy if you want to see where you are in the project, if you want to select another file in the same directory, or if you want to do a Subversion commit (since commit works on the currently selected item). You can also use
⌃⇧⌘R (or File → Reveal in Finder while holding down Shift) to reveal the file in a Finder window. On a similar note, you can use
⌃⇧O (Bundles → Shell Script → Open Terminal) to open a new Terminal window in the current directory.
Document Proxy Icons
TextMate document windows (and most OS X apps, in fact) with saved files will have a small icon representing the current file next to the filename in the window title. The icon will be faded out slightly if the document has unsaved changes (also visible by looking for the dot in the window’s close button), and solid otherwise. By dragging this icon you can use it to interact with other apps, for example if you wanted to e-mail the current document for someone you could drag the icon to the Mail dock icon, or if you wanted to open the current directory in a Finder window as a TextMate project then you could drag the proxy icon to the TextMate dock icon.
The other, more relevant, use is that you can Command-click the icon (or in fact the filename) to see a dropdown with the path to the file on disk – and you can click any item in the list to open it in Finder. This is great for quickly opening the project directory.
A Custom Command
TextMate sets many environment variables with contextual information, for use in writing commands, snippets etc. One of these environment variables is
TM_FILEPATH – as the name suggests, this contains the full path to the current file. To try it out, go to a new, empty line in a document on disk and type:
and then press
⌃R (Text → Execute Line Inserting Result) on the same line to run the command in a shell and see the result – you should get a new line below with the path to the current file.
This is handy, but if you want to view the path quickly at any time then there is a better way – we can make a new command to show us the path.
- Open the bundle editor with
⌃⌥⌘B(Bundles → Bundle Editor → Show Bundle Editor…)
- If you have not yet created a personal bundle, use the bottom left pop-up button (the plus sign with a drop-down arrow) to create a New Bundle – it should be automatically created with the current user’s name.
- Use the same button to create a New Command
- Rename the command to “Show Path to Current Document”
- Put the same command –
echo "$TM_FILEPATH"– in the big text view on the right side of the window
- Use the pop-up next to the Input: field to set the input to “None”
- Change the Output: to “Show as Tool Tip”
- You can use the field next to Key Equivalent at the bottom of the window to set a custom key equivalent for activating the command if you wish – otherwise you will have to use the bundle menu or
⌃⌘Tto activate it
- Close the bundle editor and try activating your new command – you should see a tool tip displayed with the full path to your current document.
You could also set the Output: to “Insert as Text”, or even leave it as “Show as Tool Tip” and use:
echo -n "$TM_FILEPATH" | pbcopy && echo 'Path copied to clipboard'
man pbcopy for more information on this.
8 Responses to “TextMate Tip – Where Am I?”