renv.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. 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 $(
  25. 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. )
  31. local gem_dir="$PWD/.gem/$ruby_engine/$ruby_version"
  32. export RENV_ORIG_PATH="$PATH"
  33. export RENV_ORIG_GEM_HOME="$GEM_HOME"
  34. export RENV_ORIG_GEM_PATH="$GEM_PATH"
  35. export PATH="$gem_dir/bin:$PATH"
  36. export GEM_HOME="$gem_dir"
  37. export GEM_PATH="$gem_dir:$gem_path"
  38. echo "---> renv is set, GEM_HOME is $GEM_HOME"
  39. ;;
  40. help | h | usage | --help | -h | *)
  41. echo "usage: renv [reset|status]"
  42. return
  43. ;;
  44. esac
  45. }