Last active
July 4, 2018 11:16
-
-
Save smanolloff/54a787f661a3b8b5af10541f5cc5fa2c to your computer and use it in GitHub Desktop.
MacOS: optimize RVM ruby in Sublime Text 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
rvmdir="$HOME/.rvm" | |
rubyversion=$(${rvmdir}/bin/rvm-auto-ruby -e 'puts ENV.fetch("RUBY_VERSION")') | |
export PATH="${rvmdir}/gems/${rubyversion}/bin"\ | |
":${rvmdir}/gems/${rubyversion}@global/bin"\ | |
":${rvmdir}/rubies/${rubyversion}/bin"\ | |
":${rvmdir}/bin"\ | |
":$PATH" | |
export GEM_HOME="${rvmdir}/gems/${rubyversion}" | |
export GEM_PATH="${rvmdir}/gems/${rubyversion}:${rvmdir}/gems/${rubyversion}@global" | |
export MY_RUBY_HOME="${rvmdir}/rubies/${rubyversion}" | |
export RUBY_VERSION="${rubyversion}" | |
export SUBLIME=true | |
exec "${0%/*}/Sublime Text" $@ |
Thanks for the tip, my sublime text ruby config seems to have broken with the High Sierra update (it went back to using the System Ruby I guess), but with this it works again :D
@smanolloff your solutions seems to break everytime there's a sublime text update and I have to reapply your patch :S Do you think there would be something less intrusive that could keep working even after an app update ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using
rvm-auto-ruby
in sublime build systems is inefficient as it initializes the RVM environment on each invocation and has a noticeable performance impact.My solution for Sublime Text 3 on MacOS, based on http://apple.stackexchange.com/a/51737 (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 viaruby -S <executable>
(at least on my MacOS 10.12 with updated rubygems and rvm). Haven't really investigated why, but it sometimes saves up to one second...Try it yourself: