Skip to content
Fetching contributors…
Cannot retrieve contributors at this time
180 lines (152 sloc) 5.32 KB
#!/usr/bin/env bash
#
# Environment manipulation functions.
#
__rvm_default_flags()
{
true ${rvm_head_flag:=0} ${rvm_delete_flag:=0}
}
__rvm_nuke_rvm_variables()
{
unset rvm_head_flag $(env | awk -F= '/^rvm_/{print $1" "}')
}
# Unset ruby-specific variables
__rvm_unset_ruby_variables()
{
# unset rvm_ruby_flag $(env | awk -F= '/^rvm_ruby_/{printf $1" "}')
unset rvm_env_string rvm_ruby_string rvm_ruby_strings rvm_ruby_binary rvm_ruby_gem_home rvm_ruby_gem_path rvm_ruby_home rvm_ruby_interpreter rvm_ruby_irbrc rvm_ruby_log_path 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_selected_flag rvm_ruby_tag rvm_ruby_version rvm_head_flag rvm_ruby_package_file rvm_ruby_configure rvm_ruby_name rvm_ruby_url rvm_ruby_global_gems_path rvm_ruby_args rvm_ruby_name rvm_llvm_flag
__rvm_load_rvmrc # restore important variables
}
# TODO: Should be able to...
# Unset both rvm variables as well as ruby-specific variables
# Preserve gemset if 'rvm_sticky' is set
# (persist gemset unless clear is explicitely called).
__rvm_cleanse_variables()
{
__rvm_unset_ruby_variables
if [[ ${rvm_sticky_flag:-0} -eq 1 ]]
then export rvm_gemset_name
else unset rvm_gemset_name
fi
# arrays
unset rvm_configure_flags rvm_patch_names rvm_make_flags
# variables
unset rvm_env_string rvm_ruby_string rvm_action rvm_irbrc_file rvm_command rvm_error_message rvm_force_flag rvm_all_flag rvm_reconfigure_flag rvm_bin_flag rvm_import_flag rvm_export_flag rvm_self_flag rvm_gem_flag rvm_rubygems_flag rvm_debug_flag rvm_delete_flag rvm_summary_flag rvm_test_flag _rvm_spec_flag rvm_json_flag rvm_yaml_flag rvm_shebang_flag rvm_env_flag rvm_tail_flag rvm_use_flag rvm_dir_flag rvm_list_flag rvm_empty_flag rvm_file_name rvm_benchmark_flag rvm_clear_flag rvm_name_flag rvm_verbose_flag rvm_user_flag rvm_system_flag rvm_uninstall_flag rvm_install_flag rvm_llvm_flag rvm_ruby_bits rvm_sticky_flag rvm_rvmrc_flag rvm_gems_flag rvm_only_path_flag rvm_docs_flag rvm_dump_environment_flag rvm_ruby_alias rvm_static_flag rvm_archive_extension rvm_hook rvm_ruby_name rvm_remote_flag
# rvm_gemsets_path rvm_user_path rvm_wrappers_path rvm_patches_path rvm_docs_path rvm_examples_path rvm_rubies_path rvm_usr_path rvm_src_path rvm_tmp_path rvm_lib_path rvm_repos_path rvm_log_path rvm_help_path rvm_environments_path rvm_archives_path
__rvm_load_rvmrc # restore important variables
}
# Add bin path if not present
__rvm_conditionally_add_bin_path()
{
if printf "%b" "${PATH//:/ }" | GREP_OPTIONS="" \grep -vF "${rvm_bin_path}" >/dev/null 2>&1
then
case "${rvm_ruby_string:-"system"}" in
system)
PATH="$PATH:${rvm_bin_path}"
;;
*)
PATH="${rvm_bin_path}:$PATH"
;;
esac
builtin hash -r
fi
return 0
}
__rvm_load_environment()
{
typeset string
string="$1"
if [[ -f "$rvm_environments_path/$string" ]]; then
# Restore the path to it's state minus rvm
__rvm_remove_rvm_from_path
# source the environment file
\. "$rvm_environments_path/$string"
if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
then
\. "${rvm_path:-$HOME/.rvm}/hooks/after_use"
fi
# clear the PATH cache
builtin hash -r
elif [[ -n "$string" ]] ; then
rvm "$string"
else
: # TODO: This should have some error handling in the context.
fi
return 0
}
__rvm_export()
{
# extract the variable name from the first arg.
typeset name
name=${1%%=*}
# store the current value, to be restored later.
builtin export rvm_old_$name=${!name}
# pass-through the return value of the builtin.
export "$@"
return $?
}
__rvm_unset_exports()
{
typeset wrap_name name value
while IFS== read -d "" wrap_name value
do
case "$wrap_name" in
rvm_old_*)
name=${wrap_name#rvm_old_}
if [[ -n "${value:-}" ]]
then export $name="${value}"
else unset $name
fi
unset $wrap_name
;;
esac
done < <(printenv_null)
}
# Clean all *duplicate* items out of the path. (keep first occurrence of each)
__rvm_clean_path()
{
export PATH
typeset IFS _iterator_path
typeset -a _old_path _new_path
IFS=:
_old_path=( $PATH )
for _iterator_path in "${_old_path[@]}"
do
[[ ":${_new_path[*]}:" =~ :${_iterator_path}: ]] || _new_path+=( "${_iterator_path}" )
done
PATH="${_new_path[*]}"
builtin hash -r
}
# Clean all rvm items out of the current working path.
__rvm_remove_rvm_from_path()
{
__rvm_remove_from_path "${rvm_path}"
builtin hash -r
}
__rvm_switch()
{
typeset new_rvm_path new_rvm_bin_path
(( $# )) && [[ -z "$1" ]] && shift || true # skip first empty argument
(( $# )) && [[ -n "$1" ]] && [[ -d "$1" || -d "${1%/*}" ]] && [[ ! -f "$1" ]] ||
{
rvm_error "No valid path given."
return 1
}
[[ "${rvm_path}" != "${new_rvm_path}" ]] ||
{
rvm_warn "Already there!"
return 2
}
rvm_log "Switching ${rvm_path} => ${1}"
new_rvm_path="${1%/}"
new_rvm_bin_path="${2:-$new_rvm_path/bin}"
new_rvm_bin_path="${new_rvm_bin_path%/}"
__rvm_use_system
__rvm_remove_from_path "${rvm_path}"
rvm_reload_flag=1
rvm_path="${new_rvm_path}"
rvm_bin_path="${new_rvm_bin_path}"
rvm_scripts_path="${rvm_path}/scripts"
__rvm_remove_from_path "${rvm_path}"
__rvm_add_to_path prepend "${rvm_bin_path}"
}
Jump to Line
Something went wrong with that request. Please try again.