Given the following ruby script:
#!/usr/bin/env ruby
puts RUBY_VERSION
…and that I'm setting TM_RUBY = "/Users/myname/.rvm/bin/ruby-1.9.3-p0@primes" in the .tm_properties for the project, hitting Cmd-R in the script window shows 1.8.7. Running it from the command-line shows the expected 1.9.3.
Does anybody know what's going on here? It would be lovely to be able to use TM2 with different projects using rvm, and have everything Just Work :)
[Ideally, TM2 should detect that rvm is being used and get the ruby and gemset from the project's .rvmrc, if supplied, or from rvm's defaults otherwise. Even better if the following sequence 'rvm use 1.8.7 --default; rvm use 1.9.3; mate foo' would pick up 1.9.3 from the shell's env rather than using the default.]
On Sunday June 03 2012, John Yeates textmate2@warmvomit.co.uk wrote:
#!/usr/bin/env ruby
puts RUBY_VERSION
…and that I'm setting TM_RUBY = "/Users/myname/.rvm/bin/ruby-1.9.3-p0@primes" in the .tm_properties for the project, hitting Cmd-R in the script window shows 1.8.7. Running it from the command-line shows the expected 1.9.3.
Hm — further experiments show that if I delete the shebang from the script, it runs using TM_RUBY and shows 1.9.3 (but will break for people running it from the command line). If I point the shebang at /Users/myname/.rvm/bin/ruby-1.9.3-p0@primes, it again shows 1.9.3 (but will break for people not on my machine, or on my machine but without read access to that binary).
So it's not as bad as I thought, but there still isn't a "set it and forget it" solution — and, of course, I still need to specify the binary explicitly in the .tm_properties.
For RVM's integration in textmate, please take a look at RVM's documentation: https://rvm.io/integration/textmate/
While I'm not a TM2 user anymore, the rvm-auto-ruby's approach works fine for me in TM1, but it only reads .rvmrc files at the project's root (as opposed to navigating up in the directory tree looking for other .rvmrc files)
On Sun, Jun 3, 2012 at 7:02 AM, John Yeates textmate2@warmvomit.co.uk wrote:
Given the following ruby script:
#!/usr/bin/env ruby
puts RUBY_VERSION
…and that I'm setting TM_RUBY = "/Users/myname/.rvm/bin/ruby-1.9.3-p0@primes" in the .tm_properties for the project, hitting Cmd-R in the script window shows 1.8.7. Running it from the command-line shows the expected 1.9.3.
Does anybody know what's going on here? It would be lovely to be able to use TM2 with different projects using rvm, and have everything Just Work :)
[Ideally, TM2 should detect that rvm is being used and get the ruby and gemset from the project's .rvmrc, if supplied, or from rvm's defaults otherwise. Even better if the following sequence 'rvm use 1.8.7 --default; rvm use 1.9.3; mate foo' would pick up 1.9.3 from the shell's env rather than using the default.]
-- John Yeates
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
On Sunday June 03 2012, dipnlik dipnlik@gmail.com wrote:
For RVM's integration in textmate, please take a look at RVM's documentation: https://rvm.io/integration/textmate/
While I'm not a TM2 user anymore, the rvm-auto-ruby's approach works fine for me in TM1, but it only reads .rvmrc files at the project's root (as opposed to navigating up in the directory tree looking for other .rvmrc files)
Thanks, but 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".
In that case, TextMate runs with the system ruby rather than the rvm ruby. There's nothing on the page you linked to say what *should* be after the #! so it will: a) work from TextMate on a system with rvm installed, and b) *still work* when the script is run on a system *without* rvm installed.
Does anybody know how I should set this up?
Thanks
Try this link. http://www.christopherirish.com/2010/06/28/how-to-setup-textmate-to-use-rvm/
On Jul 5, 2012, at 1:39 AM, John Yeates wrote:
On Sunday June 03 2012, dipnlik dipnlik@gmail.com wrote:
For RVM's integration in textmate, please take a look at RVM's documentation: https://rvm.io/integration/textmate/
While I'm not a TM2 user anymore, the rvm-auto-ruby's approach works fine for me in TM1, but it only reads .rvmrc files at the project's root (as opposed to navigating up in the directory tree looking for other .rvmrc files)
Thanks, but 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".
In that case, TextMate runs with the system ruby rather than the rvm ruby. There's nothing on the page you linked to say what *should* be after the #! so it will: a) work from TextMate on a system with rvm installed, and b) *still work* when the script is run on a system *without* rvm installed.
Does anybody know how I should set this up?
Thanks
-- John Yeates
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
Steve, the instructions on that link are basically outdated versions of the official documentation.
John, I never found a better solution than to edit the shebang line, adding a space between # and ! while I'm editing the script—or simply remove the line. But since this problem doesn't hit me a lot, I never went too far looking for other solutions.
Hope that helps.
On Thu, Jul 5, 2012 at 5:25 PM, Steve Riley shotgun.slade@gmail.com wrote:
Try this link. http://www.christopherirish.com/2010/06/28/how-to-setup-textmate-to-use-rvm/
On Jul 5, 2012, at 1:39 AM, John Yeates wrote:
On Sunday June 03 2012, dipnlik dipnlik@gmail.com wrote:
For RVM's integration in textmate, please take a look at RVM's documentation: https://rvm.io/integration/textmate/
While I'm not a TM2 user anymore, the rvm-auto-ruby's approach works fine for me in TM1, but it only reads .rvmrc files at the project's root (as opposed to navigating up in the directory tree looking for other .rvmrc files)
Thanks, but 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".
In that case, TextMate runs with the system ruby rather than the rvm ruby. There's nothing on the page you linked to say what *should* be after the #! so it will: a) work from TextMate on a system with rvm installed, and b) *still work* when the script is run on a system *without* rvm installed.
Does anybody know how I should set this up?
Thanks
-- John Yeates
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
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).