[TextMate] Custom Shell Variables question
Allan Odgaard
allan at macromates.com
Sat Oct 16 13:30:44 UTC 2004
On 16. Oct 2004, at 14:56, Mats Persson wrote:
> Using the above outputs the following:
>
> echo $TM_FILEPATH
> echo $TM_PROJECT_DIRECTORY
> echo $TM_FILEPATH | sed "s|^$TM_PROJECT_DIRECTORY/\(.*\)\$|\1|"
> /Volumes/WorkDisk/Users/mats/Sites/projectName/index.php
> /Volumes/WorkDisk/Users/mats/TextMateProjects
> /Volumes/WorkDisk/Users/mats/Sites/projectName/index.php
Okay, so basically the TM_PROJECT_DIRECTORY is useless in this context,
since the “logical” project directory is not where the actual tmproj
file is kept.
> Yes, however with the help of your suggestion and a bit of own brain
> activity - a rare but appreciated event - I created a work around for
> my system that works by using a custom shell variable that contains
> the path to the Sites directory.
>
> echo $TM_SITES_DIRECTORY
> /Volumes/WorkDisk/Users/mats/Sites
Ah, yes -- I think that's really the only "general" solution, seeing
how there is no way we can extract the “logical” project directory from
the existing variables.
> IMPORTANT: Possible BUG ??
>
> In the template I use ${TM_FILEPATH} and when I create a new template
> TM_FILEPATH takes the value of the currently selected Tab in the Tab
> bar.
You should use TM_NEW_FILE instead :)
> I really have to learn all the hidden shell stuff that's available in
> OS X now, as it can do much of great interest.
It's _really_ a time saver! ;)
> Do you have any recommendations about good resources for learning that
> stuff, books or online ? How did you grasp it all ?
uh... I think I learned it by years and years of reading man files ;)
I'd recommend starting by getting familiar with the GNU textutils,
unfortunately not all are available on OS X, and the OS X versions are
not always as flexible, but it's a good overview of what you'd probably
need 90% of the time:
http://www.gnu.org/software/textutils/textutils.html (you can actually
get the GNU versions for OS X btw, though I personally haven't).
Additionally there is sed and awk, which are also _very_ helpful for
manipulating text.
And for actual shell programming, I guess the bash man file has some
info, but maybe someone else can give a better reference? since man
files can be rather intimidating at first, especially when they have
the length and layout of the bash man file ;)
Also remember that often you can pipe text through a perl or ruby
script giving on the command line, which is what I do to expand the
variables in the default HTML templates (though let me add, I expect to
soon make the "output option" for templates be "insert as snippet", so
we can have placeholders, embedded shell commands a.s.o.).
Other than that, it's probably like learning any other programming
language, a bit at a time, reading through all the "public" sources
which are available (at least when they do something "impressive") and
ask questions whenever you have some!
Personally I don't mind unix questions sent to this list, since
TextMate is so tied to shell stuff.
Kind regards Allan
More information about the textmate
mailing list