Hi all. I'm trying to set a $TM_ variable in new template to get the project name (without filepath and extension) but I cannot find a way to do so. I searched through many messages in this list but I cannot find any answer to my question.
Setting ${TM_PROJECT_FILEPATH} in the template file configurator, creating the new template it will output: /Users/webrevol/Desktop/test.tmproj
Instead of: /Users/webrevol/Desktop/test.tmproj
how can I get only the filename without extension? test
Anybody? Many thanks in advance.
On Jan 25, 2007, at 12:10 PM, Web Revolution (gMail account) wrote:
Hi all. I'm trying to set a $TM_ variable in new template to get the project name (without filepath and extension) but I cannot find a way to do so. I searched through many messages in this list but I cannot find any answer to my question.
Setting ${TM_PROJECT_FILEPATH} in the template file configurator, creating the new template it will output: /Users/webrevol/Desktop/test.tmproj
Assuming you meant without the .tmproj this second time.
Instead of: /Users/webrevol/Desktop/test.tmproj
how can I get only the filename without extension? test
If this is a snippet, you would do:
${TM_PROJECT_FILEPATH/.[^.]*$//}
As it is, you would probably want to use a similar shell mechanism. Perhaps something like this:
${TM_PROJECT_FILEPATH%.tmproj}
Otherwise you need to provide us with more of an example of your situation.
Anybody? Many thanks in advance.
Haris
If this is a snippet, you would do: ${TM_PROJECT_FILEPATH/.[^.]*$//}
Dear Haris, thank you for your reply. The code above works only if a new snippet is created and it is not my case as I would like to have the project name in the new template file instead.
Otherwise you need to provide us with more of an example of your situation.
I will try to explain myself better. Within the 'Bundles Editor' I create a new 'Template' and a new 'Template File'.
In the 'Template' 'Command(s)' editor I have:
if [[ ! -f "$TM_NEW_FILE" ]]; then TM_YEAR=`date +%Y` \ TM_DATE=`date +%d" "%b" "%Y" "@" "%I:%M" "%p" "%z` \ TM_USERNAME=`niutil -readprop / /users/$USER realname` \ perl -pe 's/${([^}]*)}/$ENV{$1}/g' \ < testfile.html > "$TM_NEW_FILE" fi
and in the 'Template File' editor I have:
<!-- ${TM_PROJECT_FILEPATH} - ${TM_DATE} -->
Next... I do create a new Textmate project and I save it to desktop as 'testfile' and create a new template, selecting the new template I just created above.
The output for the new created template is: /Users/webrevol/Desktop/testfile.tmproj
..but what I would like to get is only the project filename: testfile (or testfile.tmproj)
As you see I would like to get the textmate project name on my new created file without the Path and if possible, without the filename extension.
Again, thanks for your time.
On Jan 25, 2007, at 1:41 PM, Web Revolution wrote:
In the 'Template' 'Command(s)' editor I have:
if [[ ! -f "$TM_NEW_FILE" ]]; then TM_YEAR=`date +%Y` \ TM_DATE=`date +%d" "%b" "%Y" "@" "%I:%M" "%p" "%z` \ TM_USERNAME=`niutil -readprop / /users/$USER realname` \ perl -pe 's/${([^}]*)}/$ENV{$1}/g' \ < testfile.html > "$TM_NEW_FILE" fi
Ok, add somewhere there, before the perl line, the lines:
NOEXTENSION=${TM_PROJECT_FILEPATH%.tmproj} JUSTFILENAME=${NOEXTENSION##*/} then in the template file' editor put:
and in the 'Template File' editor I have:
<!-- ${TM_PROJECT_FILEPATH} - ${TM_DATE} -->
<!-- ${JUSTFILENAME} - ${TM_DATE} -->
Next... I do create a new Textmate project and I save it to desktop as 'testfile' and create a new template, selecting the new template I just created above.
The output for the new created template is: /Users/webrevol/Desktop/testfile.tmproj
..but what I would like to get is only the project filename: testfile (or testfile.tmproj)
As you see I would like to get the textmate project name on my new created file without the Path and if possible, without the filename extension.
Again, thanks for your time.
Haris
Hello Haris, I followed your instructions but the filename still doesn't show up. I guess I can't use this feature?
On Jan 25, 2007, at 5:49 PM, Web Revolution wrote:
Hello Haris, I followed your instructions but the filename still doesn't show up. I guess I can't use this feature?
It should work. Are you sure you are in a project file, with a .tmproj extension and everything, and not just in a scratch project, created by dragging a folder onto TextMate?
You should be able to do what you want to do. Try to send me your template (drag it onto the desktop and a copy will be created), and then I'll have a look. What I described should work.
Haris
Hello Haris, the project file has been saved but it doesn't work. Find attached the template file as requested. And thank you for your kindly support!
On Jan 25, 2007, at 7:56 PM, Web Revolution wrote:
Hello Haris, the project file has been saved but it doesn't work. Find attached the template file as requested. And thank you for your kindly support!
Ok, move the two lines I suggested so that they are before the TM_YEAR line. It should sort of work there, except that it also adds the following character:
(This character appears as return on this email, and also when I try to paste it in TM, so not really sure what is going on, it appears as a little diamond for me in the template output. I guess it might be a \r). Perhaps someone with more knowledge of these things can help you out more in how to avoid getting that, and also explain to me what all those slashes at the end of each line in the template script are there for:
if [[ ! -f "$TM_NEW_FILE" ]]; then NOEXTENSION=${TM_PROJECT_FILEPATH%.tmproj} JUSTFILENAME=${NOEXTENSION##*/} TM_YEAR=`date +%Y` \ TM_DATE=`date +%d" "%b" "%Y" "@" "%I:%M" "%p" "%z` \ TM_USERNAME=`niutil -readprop / /users/$USER realname` \ perl -pe 's/${([^}]*)}/$ENV{$1}/g' \ < test.html > "$TM_NEW_FILE" fi
Haris
Hello Haris, it still does not work. The output is empty. What could be the problem?
Find attached 5 screen shots for the 5 steps.
I also tried to save the project in other locations on my HDD but the project name does not show up in the new template file.
I have the latest version of TM 1.5.4 (1324)
On Jan 26, 2007, at 8:53 AM, Web Revolution wrote:
Hello Haris, it still does not work. The output is empty. What could be the problem?
Did you remember to close the Bundle editor window before trying to use the template? Otherwise, I can't really figure out what the problem is.
Out of curiosity, why do you need it to be a template, and don't just create snippet that would insert whatever kind of thing you want?
Haris
Yes, I close the bundle editor and also click reload bundles to be sure, but it doesn't work either.
As I created many template files, every template header must have certain information, including the project name. Creating a snippet I have to call the snippet every time I do create a new template instead of having the project name alraedy there...
On Jan 26, 2007, at 9:54 AM, Web Revolution wrote:
Yes, I close the bundle editor and also click reload bundles to be sure, but it doesn't work either.
As I created many template files, every template header must have certain information, including the project name. Creating a snippet I have to call the snippet every time I do create a new template instead of having the project name alraedy there...
I just never use templates to create new files ;) When you use a template, you have to select the command from the menu and things. I would find it so much simpler to just press shift-cmd-N, followed by running the snippet via another shortcut. YMMV.
If you really need to create many files, you might want to consider simply a shell/ruby/python script that does that all at once. Anything else is really inefficient. But since I don't know your particular needs I can't really comment on that.
Haris