[SVN] Re: Problems with usage of «$(type -p "${TM_RUBY:-ruby}")» in commands
Allan Odgaard
mailinglist at textmate.org
Sat Oct 17 14:55:28 UTC 2009
On 13 Oct 2009, at 16:01, Martin Kühl wrote:
> I recently ran into problems running scripts from TM and traced the
> cause to
> having defined `ruby` as a shell function that launched `irb` when
> called
> without arguments. The investigation showed a number of uses of the
> code snippet `$(type -p "${TM_RUBY:-ruby}")`, particularly in the
> following idiom:
>
> export TM_RUBY=$(type -p "${TM_RUBY:-ruby}")
>
> I think this idiom is problematic for two reasons, both of which can
> be fixed:
>
> 1. The launch path of `ruby` can contain spaces which the above
> expression
> doesn’t mask [...]
>
> 2. [...] This problem can be worked around by using which(1) instead
> of `type -p`
It’s ironic because the reason we have used ‘type -p’ over
‘which’ is because ‘which’ had a bug related to PATH containing
spaces. A space could easily appear in the PATH for TextMate commands
since we add "$TM_SUPPORT/bin" which (for users with svn checkout)
will expand to “…/Application Support/…”.
> I’m also not sure why the ruby launch path is used in the commands
> at all
A few commands needed the fully resolved path because they would
reference it later, but go through some hoops that wouldn’t ensure
that the environment was preserved, e.g. HTML output →
TextMate.system() from JavaScript (which now does have same
environment as original command). So the TM command would ensure
TM_RUBY was setup, and all JavaScript generated would expand TM_RUBY
and insert the value of that or similar.
So basically both the resolving to full path and the use of ‘type -
p’ is for historic reasons (lack of quotes is just classic mistake).
Presumably most of this can simply be removed. Also, lots of places
where the idiom is used, it is simply copy/paste.
Adding to this, calling user’s shell startup files (so you get your
ruby alias which is causing the clash) is another thing done for
“historic reasons” (to ensure the user got same PATH in TextMate as
his “LaTeX installer” (or similar) had setup for him in Terminal)
— this is not done for commands with shebang, which we have mostly
migrated to (sort of the transition to get away from this), so today
this PATH inheritance convenience is not really the case anymore,
which makes me think it is time to actually just drop sourcing user
startup files.
More information about the textmate-dev
mailing list