renv.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. function renv() {
  2. case "$1" in
  3. status|s)
  4. [[ -n "$GEM_HOME" ]] && echo "GEM_HOME='$GEM_HOME'"
  5. [[ -n "$GEM_PATH" ]] && echo "GEM_PATH='$GEM_PATH'"
  6. echo "PATH='$PATH'" && return
  7. ;;
  8. reset|r)
  9. if [[ -z "$RENV_ORIG_PATH" ]] ; then
  10. echo ">>>> renv not set. Try: \`renv'"
  11. return 3
  12. fi
  13. [[ -n "$RENV_ORIG_GEM_HOME" ]] && GEM_HOME=$RENV_ORIG_GEM_HOME || unset GEM_HOME
  14. [[ -n "$RENV_ORIG_GEM_PATH" ]] && GEM_PATH=$RENV_ORIG_GEM_PATH || unset GEM_PATH
  15. [[ -n "$RENV_ORIG_PATH" ]] && PATH=$RENV_ORIG_PATH
  16. unset RENV_ORIG_GEM_HOME RENV_ORIG_GEM_PATH RENV_ORIG_PATH
  17. echo "---> renv is reset, GEM_HOME is ${GEM_HOME:-<unset>}"
  18. ;;
  19. "")
  20. if [[ -n "$RENV_ORIG_PATH" ]] ; then
  21. echo ">>>> renv already set, GEM_HOME is $GEM_HOME. Try: \`renv reset'"
  22. return 9
  23. fi
  24. eval $(ruby -rubygems - <<-'EOF'
  25. puts "local ruby_engine=#{defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'}"
  26. puts "local ruby_version=#{RUBY_VERSION}"
  27. puts "local gem_path='#{Gem.path.join(':')}'"
  28. EOF
  29. )
  30. local gem_dir="$PWD/.gem/$ruby_engine/$ruby_version"
  31. export RENV_ORIG_PATH="$PATH"
  32. export RENV_ORIG_GEM_HOME="$GEM_HOME"
  33. export RENV_ORIG_GEM_PATH="$GEM_PATH"
  34. export PATH="$gem_dir/bin:$PATH"
  35. export GEM_HOME="$gem_dir"
  36. export GEM_PATH="$gem_dir:$gem_path"
  37. echo "---> renv is set, GEM_HOME is $GEM_HOME"
  38. ;;
  39. help|h|usage|--help|-h|*)
  40. echo "usage: renv [reset|status]"
  41. return
  42. ;;
  43. esac
  44. }