This is the old (static) wiki. Please go here instead

TextMate
Howtos

Please add all your clever howtos, if you discovered what it takes.

How to use current date and full user name in templates: http://one.textdrive.com/pipermail/textmate/2004-October/000472.html

How to launch TextMate from the shell reading from stdin: http://one.textdrive.com/pipermail/textmate/2004-October/000323.html

How to embed the word/selection in an arbitrary start/stop tag: http://one.textdrive.com/pipermail/textmate/2004-October/000362.html

How to obtain beta versions: http://one.textdrive.com/pipermail/textmate/2004-October/000491.html

Useful Commands

PHP Tricks

PHP code completion - Ian White
I’ve created a couple of scripts that give the effect of code completion.
Description and download at http://ian.ardes.com/phpcc

PHP documentation command for selected word:
Before running command: do nothing
Command(s): open http://nl.php.net/$TM_CURRENT_WORD
Standard in/output: None/Discard
Show syntax for function - Maarten Spreij I created a (crude) PHP shell script that will get just the first few lines (function name, php versions and syntax format) from http://PHP.net, it was a snap to tie it to a tooltip command:
Before running command: do nothing
Command(s): ~/bin/pdoc $TM_CURRENT_WORD
Standard input: Selected Text
Standard output: Show as tooltip
example img at http://www.mechintosh.com/images/misc/tm.png

Open Terminal Here

Opens a Terminal window in the current file’s directory.

Before running command: Do nothing
Command(s):
    osascript -e "tell application \"Terminal\" 
      activate
      set dir to \"$(echo $TM_DIRECTORY | sed 's,[\\"],\\&,g')\" 
      do script \"cd \" & quoted form of dir
    end tell" 
Standard input: None
Standard output: Discard

Sam Stephenson

Insert File

Type a file name on a line by itself, select the line with Shift-Cmd-L, then run this command to insert the contents of the file. (I suggest assigning the key Cmd-I.)

Before running command: Do nothing
Command(s): cat | xargs cat
Standard input: Selected text
Standard output: Replace selected text

Sam Stephenson

Reload in Browsers

These Commands will refresh the current browser window in each of Safari, Firefox & IE 5, or All of them at the same time.

Reload in Safari
Before running command: Save active file
Command: 
osascript -e "set theActiveURL to \"window.location.reload();\" 
tell application \"Safari\" 
activate
do JavaScript theActiveURL in first document
end tell" 

Standard input: None
Standard output: Discard
Reload in Firefox
Before running command: Save active file
Command: 
osascript -e "set theActiveURL to \"JavaScript:window.location.reload();\" 
tell application \"Firefox\" 
activate
Get URL theActiveURL inside window 1
end tell" 

Standard input: None
Standard output: Discard

Reload in Internet Explorer
NB! As usual, IE has problems, so you need to save the following AppleScript as a .scpt file and then use the Command script below

set theActiveURL to "JavaScript:window.location.reload();" 
tell application "Internet Explorer" 
Activate
OpenURL theActiveURL toWindow -1
end tell
then add the following to the command
Before running command: Save active file
Command: 
osascript /Library/Scripts/TextMate/IE-Reload.scpt

Standard input: None
Standard output: Discard

Reload in All Browsers: Safari, Firefox & IE
NB! Because of IE’s problems you need to save the following AppleScript as a .scpt file and then use the Command script below

set theActiveURL to "JavaScript:window.location.reload();" 

-- Now do Safari reload
tell application "Safari" 
activate
do JavaScript theActiveURL in first document
end tell

-- Now do Firefox reload
tell application "Firefox" 
activate
Get URL theActiveURL inside window 1
end tell

-- Then do a M$ IE reload
tell application "Internet Explorer" 
Activate
-- opens the URL to the frontmost window and ignores Document cache;
OpenURL theActiveURL toWindow -1 Flags 1
-- GetURL theActiveURL
end tell
then add the following to the command
Before running command: Save active file
Command: 
osascript /Path/To/Reload-All.scpt

Standard input: None
Standard output: Discard

Preview Current File in Browser

These Commands will open the currently active file in a new or existing window in each of Safari, Firefox & IE 5.
To make them work, it requires that you set a Project Shell Variables IF you are using the local web server:
$TM_PROJ_SITEURL = “http://www.somesite.com/
This will only work with files in the root directory, as I can’t work out how to get a dynamic Project Shell Variable.

Preview in Safari NB! This will fail if no Safari window is available. Safari issue that needs to be worked around somehow. Anyone??
Before running command: Save active file
Command: 
osascript -e "set theSiteURL to \"$(echo $TM_PROJ_SITEURL)\" 
set theFileName to \"$(echo $TM_FILENAME)\" 
set theFilePath to \"$(echo $TM_FILEPATH)\" 
if theSiteURL is \"\" then
-- OK, we have no site URL so load the FilePath
set theActiveURL to \"file://\" & theFilePath
else
-- We have theSiteURL set
set theActiveURL to theSiteURL & theFileName
end if
tell application \"Safari\" 
activate
set the URL of document 1 to theActiveURL
end tell" 

Standard input: None
Standard output: Discard
Preview in Firefox
Before running command: Save active file
Command: 
osascript -e "set theSiteURL to \"$(echo $TM_PROJ_SITEURL)\" 
set theFileName to \"$(echo $TM_FILENAME)\" 
set theFilePath to \"$(echo $TM_FILEPATH)\" 
if theSiteURL is \"\" then
-- OK, we have no site URL so load the FilePath
set theActiveURL to theFilePath
else
-- We have theSiteURL set
set theActiveURL to theSiteURL & theFileName
end if
tell application \"Firefox\" 
activate
OpenURL theActiveURL
end tell" 

Standard input: None
Standard output: Discard
Preview in IE
Before running command: Save active file
Command:
osascript -e "set theSiteURL to \"$(echo $TM_PROJ_SITEURL)\" 
set theFileName to \"$(echo $TM_FILENAME)\" 
set theFilePath to \"$(echo $TM_FILEPATH)\" 
if theSiteURL is \"\" then
-- OK, we have no site URL so load the FilePath
set theActiveURL to \"file://\" & theFilePath
else
-- We have theSiteURL set
set theActiveURL to theSiteURL & theFileName
end if
tell application \"Internet Explorer\" 
activate
OpenURL theActiveURL toWindow -1 Flags 1
end tell" 

Standard input: None
Standard output: Discard

I hope that the above scripts/commands will help all web developers.
- by Mats 2004-11-06

Emacs Keybindings

img tag completion

here's a snippet for gif tag completion (save a copy and change gif 
refs to jpg to have a snippet for jpegs, etc). Trigger is gif in this 
case. Begin the tag and hit tab at the end of the relative image path 
and it will fill in the rest, leaving you at alt, then border, then 
end. If tag path is incorrect, will print ?s for height and width:

gif" alt="$1" height="`a=$(echo $TM_FILEPATH "$(echo 
$(perl -e 'print substr($ENV{TM_CURRENT_LINE},0,
($ENV{TM_COLUMN_NUMBER}-1))') | perl -ane 'print 
$F[($ff-1)] if $ff = @F' | perl -ne 'print $a[1]."gif" 
if @a = split(/"/,$_)')" | perl -ane 'print $F[0]." ".
$F[1]." ".$fff if $fff = split("\.\./", $F[1])' | 
perl -ane 'print join("/",@path[0..($#path-$F[2])])."/".
$F[1] if @path = split("/", $F[0])' | perl -ne 's/\.\.\///g 
? print $_ : print $_'); if [ -e "$a" ]; then 
sips -g pixelHeight "$a" | perl -ne 'print if 
s/^(.+)\W+(.+): (\d+)/$3/'; else echo '?'; fi`" 
width="`a=$(echo $TM_FILEPATH "$(echo $(perl -e 'print 
substr($ENV{TM_CURRENT_LINE},0,($ENV{TM_COLUMN_NUMBER}-1))') 
| perl -ane 'print $F[($ff-1)] if $ff = @F' | 
perl -ne 'print $a[1]."gif" if @a = split(/"/,$_)')" | 
perl -ane 'print $F[0]." ".$F[1]." ".$fff if $fff = 
split("\.\./", $F[1])' | perl -ane 'print 
join("/",@path[0..($#path-$F[2])])."/".$F[1] 
if @path = split("/", $F[0])' | perl -ne 's/\.\.\///g ? 
print $_ : print $_'); if [ -e "$a" ]; then 
sips -g pixelWidth "$a" | perl -ne 'print 
if s/^(.+)\W+(.+): (\d+)/$3/'; else echo '?'; 
fi`" border="${2:0}" />$0

Hope this is useful. Not a shell programmer, so if someone can find something more graceful, please! Does work, though…

—ira 11.6.04