#!/usr/bin/env bash

__rvm_load_rvmrc()
{
  typeset _file
  typeset -a rvm_rvmrc_files
  if (( ${rvm_ignore_rvmrc:=0} == 1 ))
  then
    return 0
  fi

  [[ -n "${rvm_stored_umask:-}" ]] || export rvm_stored_umask=$(umask)

  rvm_rvmrc_files=("/etc/rvmrc" "$HOME/.rvmrc")
  if [[ -n "${rvm_prefix:-}" ]] && ! [[ "$HOME/.rvmrc" -ef "${rvm_prefix}/.rvmrc" ]]
     then rvm_rvmrc_files+=( "${rvm_prefix}/.rvmrc" )
  fi
  for _file in "${rvm_rvmrc_files[@]}"
  do
    if [[ -s "$_file" ]]
    then
      if __rvm_grep '^\s*rvm .*$' "$_file" >/dev/null 2>&1
      then
        rvm_error "
$_file is for rvm settings only.
rvm CLI may NOT be called from within $_file.
Skipping the loading of $_file
"
        return 1
      else
        source "$_file"
      fi
    fi
  done
  return 0
}

# Initialize rvm, ensuring that the path and directories are as expected.
__rvm_initialize()
{
  true ${rvm_scripts_path:="$rvm_path/scripts"}
  source "$rvm_scripts_path/base"

  __rvm_clean_path
  __rvm_conditionally_add_bin_path
  export PATH

  if [[ ! -d "${rvm_tmp_path:-/tmp}" ]]
  then
    command mkdir -p "${rvm_tmp_path}"
  fi

  return 0
}
