开发者

How to use this path in the textmate snippets?

开发者 https://www.devze.com 2023-03-30 09:29 出处:网络
I would like to have a string that is $TM_PROJECT_DIRECTORY-$TM_F开发者_如何学JAVAILEPATH..... the $TM_PROJECT_DIRECTORY is

I would like to have a string that is $TM_PROJECT_DIRECTORY-$TM_F开发者_如何学JAVAILEPATH..... the $TM_PROJECT_DIRECTORY is

/Users/me/Desktop/project/application/app_name

and $TM_FILEPATH is /Users/me/Desktop/project/application/app_name/application/models/user_model.php

The result I want:

application/models/user_model.php


You can't do this in raw snippet syntax, but you can create snippets on the fly using the Commands.

So, to do what you want you must create «New Command», then make a snippet you want in, for example, ruby:

#!/usr/bin/env ruby
print ENV['TM_FILEPATH'].gsub(/^#{ENV['TM_PROJECT_DIRECTORY']}\//,'')

then in Input set none and in Output set Insert as Snippet.

Actually, using any programming language TextMate understand you can create a lot of powerful snippets on the fly.


${TM_FILEPATH/$TM_PROJECT_DIRECTORY\//}

See Section 7.7 "Snippets/Transformations" in the TextMate Help for details.


Just had this issue myself. Here's the snippet I used:

FILEPATH=${TM_FILEPATH/#$TM_PROJECT_DIRECTORY\//}
echo -n "$FILEPATH"

The surrounding backticks execute the shell code when Textmate inserts the snippet.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号