rvm-shell 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #!/usr/bin/env bash
  2. export HOME="${HOME%%+(\/)}" # Remove trailing slashes if they exist on HOME
  3. if
  4. (( ${rvm_ignore_rvmrc:=0} == 0 ))
  5. then
  6. for rvmrc in /etc/rvmrc "$HOME/.rvmrc"
  7. do
  8. if [[ -f "$rvmrc" ]]
  9. then
  10. if GREP_OPTIONS="" \grep '^\s*rvm .*$' "$rvmrc" >/dev/null 2>&1
  11. then
  12. printf "%b" "\nError: $rvmrc is for rvm settings only.\nrvm CLI may NOT be called from within $rvmrc. \nSkipping the loading of $rvmrc"
  13. return 1
  14. else
  15. source "$rvmrc"
  16. fi
  17. fi
  18. done
  19. fi
  20. # duplication marker jdgkjnfnkjdngjkfnd4fd
  21. export rvm_path
  22. if
  23. [[ -z "${rvm_path:-}" ]]
  24. then
  25. if [[ -d "${0%/bin/rvm-shell}" ]]
  26. then rvm_path="$( \cd "${0%/bin/rvm-shell}">/dev/null; pwd )"
  27. elif (( UID == 0 )) && [[ -d "/usr/local/rvm" ]]
  28. then rvm_path="/usr/local/rvm"
  29. elif [[ -d "${HOME}/.rvm" ]]
  30. then rvm_path="${HOME}/.rvm"
  31. elif [[ -d "/usr/local/rvm" ]]
  32. then rvm_path="/usr/local/rvm"
  33. else echo "Can't find rvm install!" 1>&2 ; exit 1
  34. fi
  35. fi
  36. rvm_path="${rvm_path%%*(/)}" # remove trailing slashes
  37. case $0 in
  38. (*-rvm-env) selected_shell=${0%-rvm-env} ;;
  39. (*) selected_shell=bash ;;
  40. esac
  41. selected_shell="$(basename "${selected_shell}")"
  42. if
  43. [[ -n "$1" && ! -f "$1" && -n "$(echo "$1" | GREP_OPTIONS="" \grep -v '^-')" ]]
  44. then
  45. rvm_shell_ruby_string="$1"
  46. shift
  47. elif
  48. [[ "$1" == "--path" ]] && [[ -d "$2" || "$2" == "/"* ]]
  49. then
  50. if
  51. [[ -d "$2" ]]
  52. then
  53. cd $2
  54. else
  55. rvm_shell_ruby_string="default"
  56. fi
  57. shift 2
  58. fi
  59. true ${rvm_scripts_path:="$rvm_path/scripts"}
  60. export rvm_scripts_path
  61. if
  62. [[ -n "$rvm_path" && -f "$rvm_scripts_path/rvm" ]]
  63. then
  64. source "$rvm_scripts_path/rvm"
  65. typeset -f rvm >/dev/null 2>&1 || {
  66. echo "RVM not loaded, aborting." >&2
  67. exit 1
  68. }
  69. # Setup as expected.
  70. if
  71. [[ -n "$rvm_shell_ruby_string" ]]
  72. then
  73. unset GEM_HOME # disable GEM_HOME mismatch check when using ruby
  74. __rvm_conditionally_do_with_env __rvm_use "$rvm_shell_ruby_string" ||
  75. {
  76. __status=$?
  77. echo "Error: RVM was unable to use '$rvm_shell_ruby_string'" 1>&2
  78. exit ${__status}
  79. }
  80. else
  81. __rvm_conditionally_do_with_env __rvm_rvmrc_tools load . >/dev/null 2>&1
  82. fi
  83. fi
  84. exec ${selected_shell} "$@"