Skip to content

Instantly share code, notes, and snippets.

@prettymuchbryce
Created May 28, 2012 03:15
Show Gist options
  • Save prettymuchbryce/2817013 to your computer and use it in GitHub Desktop.
Save prettymuchbryce/2817013 to your computer and use it in GitHub Desktop.
➜ / which rvm
rvm () {
typeset result current_result
export -a rvm_ruby_args > /dev/null 2> /dev/null
if (( ${rvm_ignore_rvmrc:=0} == 0 ))
then
: rvm_stored_umask:${rvm_stored_umask:=$(umask)}
for rvmrc in /etc/rvmrc "$HOME/.rvmrc"
do
if [[ -f "$rvmrc" ]]
then
if GREP_OPTIONS="" \grep '^\s*rvm .*$' "$rvmrc" > /dev/null 2>&1
then
printf "%b" "
Error:
$rvmrc is for rvm settings only.
rvm CLI may NOT be called from within $rvmrc.
Skipping the loading of $rvmrc"
return 1
else
source "$rvmrc"
fi
fi
done
fi
disk_version="$(cat "$rvm_path/VERSION") ($(cat "$rvm_path/RELEASE" 2>/dev/null))"
if [[ -s "$rvm_path/VERSION" && "${rvm_version:-}" != "${disk_version:-}" && "reload" != "${1:-}" ]]
then
if [[ ${rvm_auto_reload_flag:-0} -gt 0 ]]
then
__rvm_project_rvmrc_lock=0
rvm_reload_flag=1
source "${rvm_scripts_path:-${rvm_path}/scripts}/rvm"
else
printf "%b" "
A RVM version ${disk_version} is installed yet ${rvm_version} is loaded.
Please do one of the following:
* 'rvm reload'
* open a new shell
* 'echo rvm_auto_reload_flag=1 >> ~/.rvmrc' # for auto reload with msg.
* 'echo rvm_auto_reload_flag=2 >> ~/.rvmrc' # for silent auto reload.
"
return 1
fi
fi
__rvm_initialize
__rvm_setup
next_token="$1"
[[ $# -eq 0 ]] || shift
__rvm_parse_args "$@"
result=$?
rvm_action="${rvm_action:-usage}"
[[ $result -gt 0 ]] || case "$rvm_action" in
(use) if rvm_is_a_shell_function
then
__rvm_use
fi ;;
(srcdir) __rvm_source_dir ;;
(strings) __rvm_strings ;;
(version) __rvm_version ;;
(ls|list) "$rvm_scripts_path/list" "${rvm_ruby_args[@]}" ;;
(debug) rvm_is_not_a_shell_function="${rvm_is_not_a_shell_function}" "$rvm_scripts_path/info" '' debug ;;
(usage) __rvm_usage ;;
(benchmark) source "$rvm_scripts_path/functions/benchmark"
__rvm_benchmark ;;
(inspect) __rvm_inspect ;;
(update) printf "%b" "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) next_token="${1:-}"
(( $# > 0 )) && shift
[[ "$next_token" = "${rvm_action}" ]] && shift
tmpdir=${TMPDIR:-/tmp}
\cp -f "$rvm_scripts_path/get" $tmpdir/$$
if "$SHELL" "$tmpdir/$$" "${rvm_ruby_args[@]}"
then
rvm_reload_flag=1
else
rvm_error "Could not update RVM, get some help at #rvm IRC channel at freenode servers."
fi
\rm -f $tmpdir/$$ ;;
(help|rtfm|env|current|list|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[@]}" ;;
(info) rvm_is_not_a_shell_function="${rvm_is_not_a_shell_function}" "$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
"$rvm_scripts_path/set" "$rvm_action" "${rvm_ruby_args[@]}"
result=$?
[[ -n "$old_rvm_ruby_string" ]] && rvm_ruby_string=$old_rvm_ruby_string
unset old_rvm_ruby_string ;;
(rvmrc) __rvm_rvmrc_tools "${rvm_ruby_args[@]}" ;;
(gemset) if [[ ${rvm_use_flag:-0} -eq 1 ]]
then
__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 ;;
(remove) 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
rvm_ruby_string=default
__rvm_use ;;
(fetch|uninstall|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|install) export rvm_path
if [[ -n "${rvm_ruby_strings}" ]]
then
typeset save_ruby
selected_ruby="$( __rvm_select && echo $rvm_env_string )"
if [[ -z "${selected_ruby}" ]]
then
rvm_error "Could not detect ruby version/name for installation, please be more specific."
false
elif (( ${rvm_force_flag:-0} == 0 )) && "$rvm_scripts_path"/list strings | GREP_OPTIONS="" \grep "^${selected_ruby}$" > /dev/null
then
rvm_log "Already installed ${selected_ruby}.
To reinstall use:
rvm reinstall ${rvm_ruby_strings}
"
else
"$rvm_scripts_path"/manage install "${rvm_ruby_strings}"
fi
else
rvm_error "Can not use or install all rubies."
false
fi ;;
(mount|automount) "${rvm_scripts_path}/external" "$rvm_action" "${rvm_ruby_args[@]}" ;;
(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}
[[ $result -gt 0 ]] || case "$rvm_action" in
(reinstall|try_install|install) if [[ $(ls -1 $rvm_rubies_path/*/bin/ruby | wc -l) -eq 1 ]] && [[ ! -f "${rvm_environments_path}/default" ]]
then
if rvm_is_a_shell_function
then
rvm_default_flag=1 __rvm_use
fi
fi ;;
esac
current_result=$?
(( result > 0 )) || result=${current_result}
if [[ ${rvm_reload_flag:-0} -eq 1 ]]
then
__rvm_project_rvmrc_lock=0
source "$rvm_scripts_path/rvm"
fi
typeset __local_rvm_trace_flag
__local_rvm_trace_flag=${rvm_trace_flag:-0}
__rvm_teardown
if (( __local_rvm_trace_flag > 0 ))
then
set +o verbose
set +o xtrace
[[ -n "${ZSH_VERSION:-""}" ]] || set +o errtrace
fi
return ${result:-0}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment