Skip to content

Instantly share code, notes, and snippets.

@cadwallion
Created December 15, 2011 21:24
Show Gist options
  • Save cadwallion/1482967 to your computer and use it in GitHub Desktop.
Save cadwallion/1482967 to your computer and use it in GitHub Desktop.
`which rvm`
› which rvm
rvm () {
local result current_result
if [[ -n "${BASH_VERSION:-}" ]]
then
trap '__rvm_teardown_final' 0 1 2 3 15
fi
next_token="$1"
[[ $# -eq 0 ]] || shift
__rvm_initialize
__rvm_setup
disk_version=$(cat "$rvm_path/VERSION")
disk_version="${disk_version/%.}"
if [[ -n "${rvm_version:-""}" && "${rvm_version:-""}" != "${disk_version:-""}" && "reload" != "${next_token:-""}" ]]
then
printf "\nA RVM version ${disk_version} is installed yet ${rvm_version} is loaded.\n Please do one of the following:\n * 'rvm reload'\n * open a new shell\n\n"
return 1
fi
__rvm_parse_args "$@"
result=$?
rvm_action="${rvm_action:-usage}"
[[ $result -gt 0 ]] || case "$rvm_action" in
(use) if [[ "${rvm_is_not_a_shell_function:-0}" = "1" ]]
then
printf "\n$(tput setaf 1)RVM is not a function, selecting rubies with '$(tput setaf 2)rvm use ...$(tput setaf 1)' will not work.$(tput sgr0)\n\n"
else
__rvm_use
fi ;;
(srcdir) __rvm_source_dir ;;
(strings) __rvm_strings ;;
(version) __rvm_version ;;
(ls|list) "$rvm_scripts_path"/list $rvm_ruby_args ;;
(debug) "$rvm_scripts_path/info" '' debug ;;
(usage) __rvm_usage ;;
(benchmark) source "$rvm_scripts_path/functions/benchmark"
__rvm_benchmark ;;
(inspect) __rvm_inspect ;;
(update) printf "ERROR: rvm update has been removed. See 'rvm get' and rvm 'rubygems' CLI API instead\n" ;;
(reset) source "$rvm_scripts_path/functions/reset"
__rvm_reset ;;
(reboot) source "$rvm_scripts_path/functions/cleanup"
__rvm_reboot ;;
(implode|seppuku) source "$rvm_scripts_path/functions/implode"
__rvm_implode ;;
(get) if (( $# > 0 ))
then
next_token="$1"
shift
else
next_token=""
fi
if [[ "$next_token" = "${rvm_action}" ]]
then
shift
fi
tmpdir=${TMPDIR:-/tmp}
\cp -f "$rvm_scripts_path/get" $tmpdir/$$
"$SHELL" "$tmpdir/$$" $rvm_ruby_args
\rm -f $tmpdir/$$
rvm_reload_flag=1 ;;
(help|rtfm|env|current|info|list|gemdir|gemhome|gempath|monitor|notes|package|extract|pkg|requirements) if (( $# > 0 ))
then
next_token="$1"
shift
else
next_token=""
fi
if [[ "$next_token" = "${rvm_action}" ]]
then
shift
fi
"$rvm_scripts_path/${rvm_action}" ${rvm_ruby_args:-} ;;
(cleanup|tools|snapshot|disk-usage|repair|alias|docs|rubygems|migrate|upgrade) __rvm_run_script "$rvm_action" "$rvm_ruby_args" ;;
(wrapper) "$rvm_scripts_path/wrapper" "$rvm_ruby_string" "$rvm_wrapper_name" $rvm_ruby_args
unset rvm_wrapper_name ;;
(do) old_rvm_ruby_string=${rvm_ruby_string:-}
unset rvm_ruby_string
export rvm_ruby_strings
case $- in
(*i*) "$rvm_scripts_path/set" "$rvm_action" $rvm_ruby_args
result=$? ;;
(*) exec "$rvm_scripts_path/set" "$rvm_action" $rvm_ruby_args ;;
esac
[[ -n "$old_rvm_ruby_string" ]] && rvm_ruby_string=$old_rvm_ruby_string
unset old_rvm_ruby_string ;;
(rvmrc) eval "__rvm_rvmrc_tools $rvm_ruby_args" ;;
(gemset) if [[ ${rvm_use_flag:-0} -eq 1 ]]
then
__rvm_gemset_select && rvm_log "Using ${GEM_HOME%@*} with gemset ${rvm_gemset_name:-default}" && __rvm_gemset_use
else
export rvm_ruby_strings
"$rvm_scripts_path/gemsets" $rvm_ruby_args
result=$?
rvm_ruby_strings=""
if [[ ${rvm_delete_flag:-0} -eq 1 ]]
then
gem_prefix="$(echo "${GEM_HOME:-""}" | \sed 's/'${rvm_gemset_separator:-"@"}'.*$//')"
if [[ "${GEM_HOME:-""}" = "${gem_prefix}${rvm_gemset_separator:-"@"}${rvm_gemset_name}" ]]
then
rvm_ruby_gem_home="$gem_prefix"
GEM_HOME="$rvm_ruby_gem_home"
GEM_PATH="$rvm_ruby_gem_home:$rvm_ruby_gem_home${rvm_gemset_separator:-"@"}global"
export rvm_ruby_gem_home GEM_HOME GEM_PATH
fi
unset gem_prefix
fi
fi ;;
(reload) rvm_reload_flag=1 ;;
(tests|specs) rvm_action="rake"
__rvm_do ;;
(fetch|install|uninstall|remove|reinstall) export rvm_path
if [[ -n "${rvm_ruby_strings}" ]]
then
"$rvm_scripts_path"/manage "$rvm_action" "${rvm_ruby_strings//*-- }"
else
"$rvm_scripts_path"/manage "$rvm_action"
fi ;;
(try_install) export rvm_path
if [[ -n "${rvm_ruby_strings}" ]]
then
local save_ruby
selected_ruby="$( __rvm_select && echo $rvm_env_string )"
if "$rvm_scripts_path"/list strings | grep "^${selected_ruby}$" > /dev/null
then
rvm_log "Already installed ${selected_ruby}"
else
"$rvm_scripts_path"/manage install "${selected_ruby}"
fi
else
rvm_error "Can not use or install all rubies."
false
fi ;;
(export) __rvm_export "$rvm_export_args" ;;
(unexport) __rvm_unset_exports ;;
(error) false ;;
(answer) source "$rvm_scripts_path/functions/fun"
__rvm_Answer_to_the_Ultimate_Question_of_Life_the_Universe_and_Everything
result=42 ;;
(question) source "$rvm_scripts_path/functions/fun"
__rvm_ultimate_question
result=42 ;;
(*) if [[ -n "${rvm_action:-""}" ]]
then
rvm_error "unknown action '$rvm_action'"
else
__rvm_usage
fi
false ;;
esac
current_result=$?
(( result > 0 )) || result=${current_result}
if [[ ${rvm_reload_flag:-0} -eq 1 ]]
then
rvm_loaded_flag=0
source "$rvm_scripts_path/rvm"
unset rvm_reload_flag
__rvm_project_rvmrc
fi
__rvm_teardown
: rvm_trace_flag:${rvm_trace_flag:=0}
if (( rvm_trace_flag > 0 ))
then
set +o verbose
set +o xtrace
[[ -n "${ZSH_VERSION:-""}" ]] || set +o errtrace
fi
unset rvm_trace_flag
return ${result:-0}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment