Skip to content

Instantly share code, notes, and snippets.

@mschuerig
Created June 10, 2012 15:28
Show Gist options
  • Save mschuerig/2906200 to your computer and use it in GitHub Desktop.
Save mschuerig/2906200 to your computer and use it in GitHub Desktop.
Switch Gemfile.lock when rvm use'ing another ruby
#!/usr/bin/env bash
# Place this file at ~/.rvm/hooks/after_use_switch_gemfiles
# and make it executable.
#
# This version copies Ruby-specific Gemfile.lock.x to Gemfile.lock.
if [ -e "Gemfile" ]; then
. "${rvm_path}/scripts/functions/hooks/jruby"
unset current_platform gemfile_platform
if [[ "${rvm_ruby_string}" =~ "jruby" ]]; then
current_platform="jruby"
else
current_platform="mri"
fi
if [ -e "Gemfile.lock" ]; then
case $(sed -n '/^PLATFORMS/,/^$/ p' "Gemfile.lock" | sed '1d; /^$/d; s/\s*//') in
java)
gemfile_platform="jruby"
;;
ruby)
gemfile_platform="mri"
;;
esac
fi
if [ -n "$gemfile_platform" -a -e "Gemfile.lock" ]; then
/bin/cp -au "Gemfile.lock" "Gemfile.lock.${gemfile_platform}"
fi
if [ -n "$current_platform" -a -e "Gemfile.lock${current_platform}" ]; then
/bin/cp -au "Gemfile.lock.${current_platform}" "Gemfile.lock"
fi
unset current_platform gemfile_platform
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment