[TxMt] Re: TextMate 2 and rvm
mailinglist at textmate.org
Thu Jul 12 06:33:33 UTC 2012
On 5 Jul 2012, at 10:39, John Yeates wrote:
> […] the problem here is when writing plain ruby (non-rails) scripts that have to start with #!/usr/bin/env ruby so that people can run them by typing "scriptname" rather than "ruby scriptname".
Why would you give the script a “use whatever is on the system” shebang yet require it to be run with a specific ruby version in TextMate?
> In that case, TextMate runs with the system ruby rather than the rvm ruby.
To be clear, it runs with the ‘ruby’ found in PATH (the /usr/bin/env command is used only to search PATH for its argument and hand over the execution to the executable found).
So if you want to use an ‘env’-shebang and control which ruby is used, the only way is to modify PATH.
We generally do not recommend altering PATH other than e.g. appending /usr/texbin and other simpler things.
There are two reasons for this, 1) most TextMate scripts use an ‘env’-shebang and not all have been updated to run with the latest available version of the interpreter, 2) scripts may call out to tar, rsync, make, and similar (w/o specifying path) and e.g. MacPorts provide replacement executables for most things on the system, but these are (often) the gnu-version and there might be subtle differences (sometimes in the arguments), so again there might be issues with some scripts if making drastic changes to PATH that cause non-standard binaries to be used over the standard ones.
As for #1, we do this for historical reasons: early versions of OS X shipped with ruby 1.8.6 or so, which lacked erb, but we used erb so much that while TextMate supported the older OS version, bundles required the user to update the installed ruby. Another reason is that many users actually deleted ‘/usr/bin/ruby’, but this is very misguided and I hope this is a thing of the past (some prominent web site had “steps to install rails” or similar, which included this advice).
So I am thinking that we should update all bundle commands to hardcode the ruby used to /usr/bin/ruby.
This would mean users can safely put something like this in ~/.tm_properties:
PATH = "$HOME/.rvm/bin:$PATH"
Caution: I actually have no idea how rvm is implemented; I failed to find a “behind the scenes” in their documentation, but I assume there is an executable in the above directory (~/.rvm/bin/ruby) which is the “driver” that read .rvmrc files and whatnot, to find out which version of ruby to actually run.
You can also put the above (.tm_properties) in your project’s root directory, and PATH is only changed for that project.
Note that if you do this now, it will also change the version of ruby used for running TextMate bundle commands; many have seen 1.9 patches, so it probably works fine 98% of the time (and if it fails, pull requests are always welcomed).
More information about the textmate