-
-
Save pmarreck/2367908 to your computer and use it in GitHub Desktop.
# Get Sublime to use your rvm ruby... Change your ~/Library/Application Support/Sublime Text 2/Packages/Ruby/Ruby.sublime-build | |
# (for ST3: ~/Library/Application Support/Sublime Text 3/Packages/User/Ruby.sublime-build) to this, replacing YOURUSERNAME. | |
# I am still looking to optimize this further... For example, avoiding hardcoding by using something like $HOME, although | |
# I have yet to get any form of that to work. | |
{ | |
"working_dir": "${project_path}", | |
"cmd": [ | |
"/Users/YOURUSERNAME/.rvm/bin/rvm-auto-ruby", "-Ilib:test", "$file" | |
], | |
// "path": "/Users/YOURUSERNAME/.rvm/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin", | |
"file_regex": "^(...*?):([0-9]*):?([0-9]*)", | |
"selector": "source.ruby" | |
} |
This didn't work for me as it was looking for bundle in /bin, /usr/bin, /usr/sbin, /sbin, despite environment variables for $PATH being set correctly. I decided to look else where and found this that works: http://rubenlaguna.com/wp/2012/02/01/sublime-text-2-rvm-rspec/
For Sublime Text 3 I just dropped it in ~/Library/Application/Support/Sublime Text 3/Packages/User/ - works great!
You're missing a comma
"cmd": [
"bundle", "exec", "$HOME/.rvm/bin/rvm-auto-ruby", "$file"
], # <-- here
Thanks for the tips!
I get "Could not locate Gem file"
I found this on another site and it worked fine:
{
"cmd": [ "/Users/xxxxxxx/.rvm/bin/rvm-auto-ruby", "$file" ],
"file_regex": "^(...?):([0-9]):?([0-9]*)",
"selector": "source.ruby"
}
For sublime linter, you have to add
{
"sublimelinter_executable_map": {
"ruby": "/Users/YOURUSERNAME/.rvm/bin/ruby"
}
}
... to the sublime linter settings as well.
I tweaked the original gist, it now works on my Sublime Text 3 editor
All you need is "env": { "PATH": "${HOME}/.rvm/bin:${PATH}" }
to dodge the whole USERNAME
nonsense. See my fork for the full details.
For whatever reason - I did not have /Users/MYUSER/.rvm
rvm installed itself into /usr/local/rvm
So my solution was to create a symbolic link:
$ ln -s /usr/local/rvm/ .rvm
From my $HOME dir
I also used the code at the very top of this gist, but if you still have issues when starting ST3 where it says it's using a version of Ruby other than what you think it should use, check to ensure that .rvm exists where people are saying it should exist.
I did nothing custom on my rvm installation - just followed the guide and left everything at default.
Slightly more sophisticated example for ST2 for Rails developers (Ctrl+Shift+B
will call rails runner
):
{ "file_regex": "^(...*?):([0-9]*):?([0-9]*)", "selector": "source.ruby", "shell": true, "cmd": ["rvm . do bundle exec ruby $file"], "variants": [ { "name": "Run", "cmd": ["rvm . do bundle exec rails runner $file"] } ] }
Fixed the $HOME problem:
{
"working_dir": "${project_path}",
"cmd": [
"rvm-auto-ruby", "$file"
],
"path": "${HOME}/.rvm/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin",
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.ruby"
}
Where are the gemfiles in Text Sublime 2?
I am just getting ready to learn Web Developing with the Odin Project. At this time I am installing everything and I am at the Title: "Prepare your rails app for deploying to Heroku." It says to "Launch your text editor and open the "Gemfile" file located inside of your test_app folder." I am using Text Sublime 2 but I am unable to find the Gemfiles or even the test_app. Thanks for your help.
Using rvm-auto-ruby
is inefficient as it initializes the RVM environment on each invocation and has a noticeable performance impact.
Here is my solution for Sublime Text 3 on MacOS (commands require superuser privileges):
-
Create file
/Applications/Sublime Text.app/Contents/MacOS/setenv.sh
with the contents of this gist -
chmod +x "/Applications/Sublime Text.app/Contents/MacOS/setenv.sh"
-
Edit
/Applications/Sublime Text.app/Contents/Info.plist
, changing theCFBundleExecutable
value tosetenv.sh
-
Force update the LaunchService database in the Terminal by using the lsregister command:
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f '/Applications/Sublime Text.app'
-
(Re-)launch Sublime Text. Observe how the correct ruby (as set by rvm) invocations are almost instant within sublime :)
Bonus hint:
Invocations of various ruby executables (bundle
, rspec
, etc.) are much faster when done via ruby -S <executable>
(at least for me on MacOS 10.12 with updated rubygems and rvm). Haven't really investigated why, but it sometimes saves up to one second...
Try it yourself:
command time ruby -S bundle exec rake --help >/dev/null
# 1.06 real 0.59 user 0.09 sys
command time bundle exec rake --help >/dev/null
# 2.14 real 1.15 user 0.09 sys
Hope this helps.
For some reason I had to replace
$HOME
for/Users/username
on Mac.