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'"
  7. return
  8. ;;
  9. reset|r)
  10. if [[ -z "$RENV_ORIG_PATH" ]] ; then
  11. echo ">>>> renv not set. Try: \`renv'"
  12. return 3
  13. fi
  14. [[ -n "$RENV_ORIG_GEM_HOME" ]] && GEM_HOME=$RENV_ORIG_GEM_HOME || unset GEM_HOME
  15. [[ -n "$RENV_ORIG_GEM_PATH" ]] && GEM_PATH=$RENV_ORIG_GEM_PATH || unset GEM_PATH
  16. [[ -n "$RENV_ORIG_PATH" ]] && PATH=$RENV_ORIG_PATH
  17. unset RENV_ORIG_GEM_HOME RENV_ORIG_GEM_PATH RENV_ORIG_PATH
  18. echo "---> renv is reset, GEM_HOME is ${GEM_HOME:-<unset>}"
  19. ;;
  20. "")
  21. if [[ -n "$RENV_ORIG_PATH" ]] ; then
  22. echo ">>>> renv already set, GEM_HOME is $GEM_HOME. Try: \`renv reset'"
  23. return 9
  24. fi
  25. eval $(ruby -rubygems - <<-'EOF'
  26. puts "local ruby_engine=#{defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'}"
  27. puts "local ruby_version=#{RUBY_VERSION}"
  28. puts "local gem_path='#{Gem.path.join(':')}'"
  29. EOF)
  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. }