Skip to content

Instantly share code, notes, and snippets.

@pmarreck
Last active December 10, 2023 20:00
Show Gist options
  • Save pmarreck/2367908 to your computer and use it in GitHub Desktop.
Save pmarreck/2367908 to your computer and use it in GitHub Desktop.
Get Sublime Text 2 (or 3) to use your RVM ruby and bundle Gemfile
# 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"
}
@smanolloff
Copy link

smanolloff commented Mar 11, 2017

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):

  1. Create file /Applications/Sublime Text.app/Contents/MacOS/setenv.sh with the contents of this gist

  2. chmod +x "/Applications/Sublime Text.app/Contents/MacOS/setenv.sh"

  3. Edit /Applications/Sublime Text.app/Contents/Info.plist, changing the CFBundleExecutable value to setenv.sh

  4. 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'
  5. (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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment