[TxMt] "File->New From Template" shell script "issue"...

John Wiederhirn jfw at kompositor.com
Sat Jan 16 01:42:41 UTC 2010

I'm not quite sure if this is a bug per-se, but I ran into a problem
attempting to create C & CPP template files, related to how the existing
Objective-C template shell works (and interacting with it):

When you create a new file from template using File->New From Template->foo
the environment variables for $TM_NEW_FILE and $TM_NEW_FILE_DIRECTORY seem
to get interpreted such that they wind up pointing at a directory under that
user's /tmp.  The problem is that if any template shell script has already
created an "untitled<n>.h" file there, that file causes the new template
shell script's "exist" test to fail, and you wind up loading the (colliding)
file generated by the prior template shell script.  When dealing with three
different template types (C, C++, and Objective-C) all who expect to also
generate a .h file, the chance of such a collision becomes very high.

I looked at possibly using a timestamp to try and differentiate, but that
causes a problem if the user actually triggers the template shell script
from the Project window.  In that case, the script receives
properly-populated $TM_NEW_FILE and $TM_NEW_FILE_DIRECTORY variables, and
thus you don't have the same problem of trying to avoid "tmp" naming

It seems like there are a couple of obvious solutions:

1.  TextMate could populate a variable to indicate whether the template is
being run from the Project window (in which case $TM_NEW_FILE and kin are
properly populated, and should be unique), or from the "File->New From
Template" menu item (in which case they are not, and you need to avoid
collisions because all template scripts are dumping in the same tmp
directory, using "untitled"-based names).

2.  Alternately, in the "File->New From Template" case, TextMate itself
could initially provide a _unique_ $TM_NEW_FILE_BASENAME and friends
(perhaps append a `date "+%y%m%d%H%M%S"` to the basename?).  That would
prevent collisions in the tmp directory even when multiple templates
provided files with overlapping file extensions.

There also appears to be an issue over time of these left-over template
shell script file "breadcrumbs" created when "untitled<n>.foo" files are
initially created, but the user presumably saves the file with a real name
afterwards.  There really doesn't appear to be any way for template scripts
to clean up the tmp dir after themselves.  Not a big deal if the filename
collision problem gets solved, but eventually they'll start to create a fair
amount of "Spotlight clutter", etc. which can become an issue.

Love the program, and am quite impressed by how much is already possible
with V1's facilities.  That said, I'm really looking forward to V2 and the
more powerful snippets/templates/etc.  I've been rather spoiled by Slickedit
on PC, and keep hoping TextMate will offer similar abilities (I refuse to
use that X-Window abortion Slickedit calls a "Mac version").


-John W.
View this message in context: http://old.nabble.com/%22File-%3ENew-From-Template%22-shell-script-%22issue%22...-tp27185975p27185975.html
Sent from the textmate users mailing list archive at Nabble.com.

More information about the textmate mailing list