Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: d21fac71da
Fetching contributors…

Cannot retrieve contributors at this time

383 lines (306 sloc) 12.488 kb
#!/usr/bin/env bash
__rvm_env_string()
{
typeset _path _string
_path="${GEM_HOME:-""}"
_string="${_path//*gems\//}"
_string="${_string//\/*/}"
printf "%b" "${_string:-system}"
}
__rvm_expand_ruby_string()
{
typeset string current_ruby
string="$1"
case "${string:-all}" in
all)
"$rvm_scripts_path/list" strings | tr ' ' "\n"
;;
all-gemsets)
"$rvm_scripts_path/list" gemsets strings
;;
default-with-rvmrc|rvmrc)
"$rvm_scripts_path/tools" path-identifier "$PWD"
;;
all-rubies|rubies)
"$rvm_scripts_path/list" rubies strings
;;
current-ruby|gemsets)
current_ruby="$(__rvm_env_string)"
current_ruby="${current_ruby%@*}"
rvm_silence_logging=1 "$rvm_scripts_path/gemsets" list strings \
| \sed "s/ (default)//; s/^/$current_ruby${rvm_gemset_separator:-@}/ ; s/@default// ;"
;;
current)
__rvm_env_string
;;
aliases)
awk -F= '{print $string}' < "$rvm_path/config/alias"
;;
*)
__rvm_ruby_strings_exist $( echo "$string" | tr "," "\n" | __rvm_strip )
;;
esac
}
__rvm_become()
{
# set rvm_rvmrc_flag=0 to not create .rvmrc in random places of code
typeset string rvm_rvmrc_flag
string="$1"
rvm_rvmrc_flag=0
[[ -n "$string" ]] && rvm_ruby_string="$string"
__rvm_use > /dev/null 2>&1
rvm_ruby_string="${rvm_ruby_string}${rvm_gemset_name:+${rvm_gemset_separator:-'@'}}${rvm_gemset_name:-}"
return 0
}
__rvm_ensure_has_environment_files()
{
typeset environment_id file_name directory identifier variable value variables
environment_id="$(__rvm_env_string)"
file_name="${rvm_environments_path}/$environment_id"
if [[ ! -d "$rvm_environments_path" ]]
then
\mkdir -p "$rvm_environments_path"
fi
if [[ ! -s "$file_name" ]] || ! GREP_OPTIONS="" \grep 'rvm_env_string=' "$file_name" >/dev/null
then
rm -f "$file_name"
printf "%b" \
"export PATH ; PATH=\"${rvm_ruby_gem_home}/bin:${rvm_ruby_global_gems_path}/bin:${rvm_ruby_home}/bin:${rvm_bin_path}:\$PATH\"\n" \
> "$file_name"
for variable in rvm_env_string rvm_path rvm_ruby_string rvm_gemset_name \
RUBY_VERSION GEM_HOME GEM_PATH MY_RUBY_HOME IRBRC MAGLEV_HOME RBXOPT
do
eval "export $variable"
eval "value=\${${variable}:-""}"
if [[ -n "$value" ]]
then
printf "export %b ; %b='%b'\n" "${variable}" "${variable}" "${value}" >> "$file_name"
else
printf "unset %b\n" "${variable}" >> "$file_name"
fi
done
fi
# Next, ensure we have default wrapper files. Also, prevent it from recursing.
if (( ${rvm_create_default_wrappers:=0} == 1 )) ||
[[ ! -f "$rvm_wrappers_path/$environment_id/ruby" ]]
then
# We need to generate wrappers for both the default gemset and the global gemset.
for identifier in "$environment_id" "${environment_id//@*/}@global"
do
rvm_create_default_wrappers=1
directory="$rvm_wrappers_path/$identifier"
if [[ ! -L "$directory" && ! -d "$directory" ]]; then
\mkdir -p "$directory"
"$rvm_scripts_path/wrapper" "$identifier" &> /dev/null
fi
done
rvm_create_default_wrappers=0
fi
return 0
}
# Loop over the currently installed rubies and refresh their binscripts.
__rvm_bin_scripts()
{
for rvm_ruby_binary in "$rvm_rubies_path"/*/bin/ruby
do
if [[ -x "$rvm_ruby_binary" ]]
then
rvm_ruby_string=$(
dirname "$rvm_ruby_binary" | xargs dirname | xargs basename
)
__rvm_select
__rvm_bin_script
fi
done
return 0
}
# Write the bin/ wrapper script for currently selected ruby.
# TODO: Adjust binscript to be able to handle all rubies,
# not just the standard interpreteres.
__rvm_bin_script()
{
"$rvm_scripts_path/wrapper" "$rvm_ruby_string"
}
# Runs a command in a given env.
__rvm_run_with_env()
{
typeset name environment _command message log path
name="${1:-""}"
environment="${2:-""}"
_command="${3:-""}"
message="${4:-""}"
[[ -n "$environment" ]] || environment="$(__rvm_env_string)"
if [[ -n "$message" ]] ; then rvm_log "$message" ; fi
if (( ${rvm_debug_flag:=0} == 1 ))
then
rvm_debug "Executing: $_command in environment $environment"
fi
path="${rvm_log_path}/$rvm_ruby_string"
log="$path/$name.log"
if [[ ! -d "$path" ]]
then
command mkdir -p "$path"
fi
if [[ ! -f "$log" ]]
then
command touch "$log" # for zsh :(
fi
printf "%b" "[$(date +'%Y-%m-%d %H:%M:%S')] $_command # under $environment\n" >> "${log}"
if (( ${rvm_niceness:=0} > 0 ))
then
_command="nice -n $rvm_niceness $_command"
fi
(
rvm_ruby_string="$environment"
__rvm_use
eval "$_command" >> "${log}" 2>&1
)
result=$?
if (( result > 0 ))
then
rvm_error "Error running '$command' under $env_name,\nplease read $log"
fi
return ${result:-0}
}
# Set shell options that RVM needs temporarily, these are reverted by __rvm_teardown.
# see the top of ./scripts/initialize for settings that are needed all the time.
# Setup must be always called after initialize, otherwise it does nothing ... except exporting.
__rvm_setup()
{
# NOTE: the same set is located below - maker kjfdngkjd
export rvm_head_flag rvm_ruby_selected_flag rvm_user_install_flag rvm_path_flag rvm_static_flag rvm_default_flag rvm_loaded_flag rvm_llvm_flag rvm_skip_autoreconf_flag rvm_18_flag rvm_19_flag rvm_force_autoconf_flag rvm_autoconf_flags rvm_dump_environment_flag rvm_verbose_flag rvm_debug_flag rvm_trace_flag rvm_pretty_print_flag rvm_create_flag rvm_remove_flag rvm_gemdir_flag rvm_reload_flag rvm_auto_reload_flag rvm_ignore_gemsets_flag rvm_install_on_use_flag
export rvm_gems_cache_path rvm_gems_path rvm_man_path rvm_ruby_gem_path rvm_ruby_log_path rvm_ruby_load_path rvm_gems_cache_path rvm_archives_path rvm_docs_path rvm_environments_path rvm_examples_path rvm_gems_path rvm_gemsets_path rvm_help_path rvm_hooks_path rvm_lib_path rvm_log_path rvm_patches_path rvm_repos_path rvm_rubies_path rvm_scripts_path rvm_src_path rvm_tmp_path rvm_user_path rvm_usr_path rvm_wrappers_path rvm_externals_path
export rvm_ruby_strings rvm_ruby_binary rvm_ruby_gem_home rvm_ruby_home rvm_ruby_interpreter rvm_ruby_irbrc rvm_ruby_major_version rvm_ruby_minor_version rvm_ruby_package_name rvm_ruby_patch_level rvm_ruby_release_version rvm_ruby_repo_url rvm_ruby_repo_branch rvm_ruby_revision rvm_ruby_tag rvm_ruby_sha rvm_ruby_version rvm_ruby_require rvm_ruby_package_file rvm_ruby_name rvm_ruby_name rvm_ruby_args rvm_ruby_user_tag rvm_ruby_patch detected_rvm_ruby_name
export __rvm_env_loaded next_token rvm_error_message rvm_gemset_name rvm_parse_break rvm_token rvm_action rvm_export_args rvm_gemset_separator rvm_expanding_aliases rvm_architectures rvm_patch_names rvm_tar_command rvm_tar_options rvm_ree_options rvm_patch_original_pwd rvm_project_rvmrc rvm_archive_extension rvm_autoinstall_bundler_flag rvm_codesign_identity rvm_expected_gemset_name
# Setup only on first load.
if (( __rvm_env_loaded != 1 ))
then return 0
fi
if [[ -n "${BASH_VERSION:-}" ]] && ! __function_on_stack cd pushd popd
then
trap 'status=$? ; __rvm_teardown_final ; set +x ; return $status' 0 1 2 3 15
fi
if [[ -n "${ZSH_VERSION:-}" ]]
then
export rvm_zsh_clobber rvm_zsh_nomatch
# Set clobber for zsh users, for compatibility with bash's append operator ( >> file ) behavior
if setopt | GREP_OPTIONS="" \grep -s '^noclobber$' >/dev/null 2>&1
then rvm_zsh_clobber=0
else rvm_zsh_clobber=1
fi
setopt clobber
# Set no_nomatch so globs that don't match any files don't print out a warning
if setopt | GREP_OPTIONS="" \grep -s '^nonomatch$' >/dev/null 2>&1
then rvm_zsh_nomatch=0
else rvm_zsh_nomatch=1
fi
setopt no_nomatch
fi
}
__rvm_teardown()
{
if builtin command -v __rvm_cleanup_tmp >/dev/null 2>&1
then
__rvm_cleanup_tmp
fi
export __rvm_env_loaded
# if __rvm_env_loaded is not set - detect it via rvm_tmp_path
: __rvm_env_loaded:${__rvm_env_loaded:=${rvm_tmp_path:+1}}:
: __rvm_env_loaded:${__rvm_env_loaded:=0}:
# decrease load count counter
: __rvm_env_loaded:$(( __rvm_env_loaded-=1 )):
#skip teardown when already done or when not yet finished
if [[ -z "${rvm_tmp_path:-}" ]] || (( __rvm_env_loaded > 0 ))
then
return 0
fi
if [[ -n "${BASH_VERSION:-}" ]]
then
trap - 0 1 2 3 15 # Clear all traps, we do not want to go into an loop.
fi
if [[ -n "${ZSH_VERSION:-""}" ]]
then
# If rvm_zsh_clobber is 0 then "setopt" contained "noclobber" before rvm performed "setopt clobber".
(( rvm_zsh_clobber == 0 )) && setopt noclobber
# If rvm_zsh_nomatch is 0 then "setopt" contained "nonomatch" before rvm performed "setopt nonomatch".
(( rvm_zsh_nomatch == 0 )) || setopt nomatch
unset rvm_zsh_clobber rvm_zsh_nomatch
fi
if [[ -n "${rvm_stored_umask:-}" ]]
then
umask ${rvm_stored_umask}
fi
# TODO: create a cleanse array for this instead of the current hard coded
# method. The array will be appended to whenever variables are used that
# should be cleaned up when the current RVM commadn is done.
# Cleanse and purge! (may be some redundancy here)
#
# NOTE: Removing rvm_bin_path here causes system wide installations to generate
# a corrupt PATH, breaking the RVM installation.
#
# NOTE: the same set is located above - maker kjfdngkjd
unset rvm_head_flag rvm_ruby_selected_flag rvm_user_install_flag rvm_path_flag rvm_static_flag rvm_default_flag rvm_loaded_flag rvm_llvm_flag rvm_skip_autoreconf_flag rvm_18_flag rvm_19_flag rvm_force_autoconf_flag rvm_autoconf_flags rvm_dump_environment_flag rvm_verbose_flag rvm_debug_flag rvm_trace_flag rvm_pretty_print_flag rvm_create_flag rvm_remove_flag rvm_gemdir_flag rvm_reload_flag rvm_auto_reload_flag rvm_ignore_gemsets_flag rvm_install_on_use_flag
unset rvm_gems_cache_path rvm_gems_path rvm_man_path rvm_ruby_gem_path rvm_ruby_log_path rvm_ruby_load_path rvm_gems_cache_path rvm_archives_path rvm_docs_path rvm_environments_path rvm_examples_path rvm_gems_path rvm_gemsets_path rvm_help_path rvm_hooks_path rvm_lib_path rvm_log_path rvm_patches_path rvm_repos_path rvm_rubies_path rvm_scripts_path rvm_src_path rvm_tmp_path rvm_user_path rvm_usr_path rvm_wrappers_path rvm_externals_path
unset rvm_ruby_strings rvm_ruby_binary rvm_ruby_gem_home rvm_ruby_home rvm_ruby_interpreter rvm_ruby_irbrc rvm_ruby_major_version rvm_ruby_minor_version rvm_ruby_package_name rvm_ruby_patch_level rvm_ruby_release_version rvm_ruby_repo_url rvm_ruby_repo_branch rvm_ruby_revision rvm_ruby_tag rvm_ruby_sha rvm_ruby_version rvm_ruby_require rvm_ruby_package_file rvm_ruby_name rvm_ruby_name rvm_ruby_args rvm_ruby_user_tag rvm_ruby_patch detected_rvm_ruby_name
unset __rvm_env_loaded next_token rvm_error_message rvm_gemset_name rvm_parse_break rvm_token rvm_action rvm_export_args rvm_gemset_separator rvm_expanding_aliases rvm_architectures rvm_patch_names rvm_tar_command rvm_tar_options rvm_ree_options rvm_patch_original_pwd rvm_project_rvmrc rvm_archive_extension rvm_autoinstall_bundler_flag rvm_codesign_identity rvm_expected_gemset_name
if builtin command -v __rvm_cleanup_download >/dev/null 2>&1
then
__rvm_cleanup_download
fi
return 0
}
__rvm_teardown_final()
{
__rvm_env_loaded=1
unset __rvm_project_rvmrc_lock
__rvm_teardown
}
__rvm_do_with_env_before()
{
if [[ -n "${rvm_scripts_path:-}" || -n "${rvm_path:-}" ]]
then
# Load env - setup all required variables, __rvm_teardown is called on the end
source "${rvm_scripts_path:-"$rvm_path/scripts"}/initialize"
__rvm_setup
fi
}
__rvm_do_with_env_after()
{
__rvm_teardown
}
__rvm_do_with_env()
{
typeset result
__rvm_do_with_env_before
"$@"
result=$?
__rvm_do_with_env_after
return ${result:-0}
}
__rvm_conditionally_do_with_env()
{
if (( __rvm_env_loaded > 0 ))
then
"$@"
else
__rvm_do_with_env "$@"
fi
}
__rvm_ensure_is_a_function()
{
if [[ ${rvm_reload_flag:=0} == 1 ]] || ! is_a_function rvm
then
for script in version selector selector_gemsets cd cli override_gem
do
if [[ -f "$rvm_scripts_path/$script" ]]
then
source "$rvm_scripts_path/$script"
else
printf "%b" \
"WARNING:
Could not source '$rvm_scripts_path/$script' as file does not exist.
RVM will likely not work as expected.\n"
fi
done
fi
}
Jump to Line
Something went wrong with that request. Please try again.