rvm-exec 2.0 KB

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