Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 238 lines (188 sloc) 5.615 kB
#!/usr/bin/env bash
unset rvm_default_flag rvm_wrapper_name
source "$rvm_scripts_path/base"
usage() {
printf "%b" "
Usage:
rvm alias [action] [arguments]
Examples:
rvm alias create [alias_name] [ruby]
rvm alias delete [alias_name]
rvm alias show [alias_name]
rvm alias list
"
}
alias_show() {
typeset expanded_alias_name
if [[ -z "$alias_name" ]]
then
rvm_log "usage: 'rvm alias show [alias_name]'"
result=1
return
fi
[[ -s "$rvm_path/config/alias" ]] || return 0
expanded_alias_name="$("$rvm_scripts_path"/db "$rvm_path/config/alias" "$alias_name")"
if [[ -z "$expanded_alias_name" ]]; then
rvm_error "Unknown alias name: '$alias_name'"
result=1
else
result=0
if [[ -n "$gemset_name" ]] ; then
printf "%b" "${expanded_alias_name}${rvm_gemset_separator:-"@"}${gemset_name}\n"
else
printf "%b" "${expanded_alias_name}\n"
fi
fi
}
alias_after_delete_default()
{
rvm_log "Deleting default links/files"
for _path in $rvm_bin_path/default_*
do
[[ -f "$_path" ]] && rm -rf ${_path}
done
for wrapper in "$rvm_path"/wrappers/default/*
do
wrapper="${wrapper##*\/}"
if [[ -L "$rvm_bin_path/${wrapper}" ]]
then
rm -f "$rvm_bin_path/${wrapper}"
fi
rm -f "$rvm_bin_path/${wrapper}"
# If the RVM bin path is different from rvm_path/bin, ensure they are
# in sync.
if [[ "${rvm_bin_path}" != "${rvm_path}/bin" ]]
then
rm -f "${rvm_path}/bin/${wrapper}"
fi
done
}
alias_delete() {
rvm_log "Deleting alias: $alias_name"
for _path in "$rvm_rubies_path" "$rvm_environments_path" "$rvm_wrappers_path"
do
[[ -L "$_path/$alias_name" ]] && rm -f "$_path/$alias_name"
done
[[ -s "$rvm_path/config/alias" ]] || return 0
"$rvm_scripts_path"/db "$rvm_path/config/alias" "$alias_name" "delete"
if [[ "default" == "$alias_name" ]] ; then
alias_after_delete_default
fi
}
alias_after_create_default()
{
rvm_log "Creating default links/files"
environment_id="${final_environment_identifier}"
if (( ${rvm_user_install_flag:=0} == 0 ))
then
# Sets up the default wrappers.
"$rvm_scripts_path/wrapper" "$rvm_ruby_string" --no-prefix
else
"$rvm_scripts_path/wrapper" "$rvm_ruby_string" "default"
fi
RUBY_VERSION="$("$rvm_ruby_home/bin/ruby" -v | \sed 's#^\(.*\) (.*$#\1#')"
export GEM_HOME GEM_PATH MY_RUBY_HOME RUBY_VERSION
# Copy wrapper scripts for the newly set default to the RVM bin path.
for wrapper in "$rvm_path"/wrappers/default/*
do
[[ -r "${wrapper}" ]] || continue
if [[ -L "$rvm_bin_path/${wrapper##*\/}" ]]
then
rm -f "$rvm_bin_path/${wrapper##*\/}"
fi
cp -f "$wrapper" "$rvm_bin_path/${wrapper##*\/}"
# If the RVM bin path is different from rvm_path/bin, ensure they are
# in sync.
if [[ "${rvm_bin_path}" != "${rvm_path}/bin" ]]
then
cp -f "${wrapper}" "${rvm_path}/bin/"
fi
done
}
alias_create()
{
alias_name="${alias_name:-""}"
rvm_ruby_string="$rvm_environment_identifier"
rvm_expanding_aliases=1
__rvm_become
unset rvm_expanding_aliases
if
[[ -z "${rvm_environment_identifier:-""}" || -z "$rvm_ruby_string" || -z "$alias_name" ]]
then
rvm_error "usage: 'rvm alias [alias_name] [ruby_string]'"
return 1
elif
[[ ! -L "$rvm_rubies_path/$alias_name" && -d "$rvm_rubies_path/$alias_name" ]]
then
rvm_error "$alias_name is a full ruby name and can not be used as alias name."
return 2
else
final_environment_identifier="${rvm_ruby_string:-$(__rvm_env_string)}"
rvm_log "Creating alias $alias_name for $final_environment_identifier."
for _path in "$rvm_rubies_path" "$rvm_environments_path" "$rvm_wrappers_path"
do
[[ -L "$_path/default" ]] && rm -f "$_path/$alias_name"
\ln -fs "$_path/$rvm_ruby_string" "$_path/$alias_name"
done
rvm_log "Recording alias $alias_name for $final_environment_identifier."
"$rvm_scripts_path"/db "$rvm_path/config/alias" "$alias_name" "$final_environment_identifier"
[[ "default" != "$alias_name" ]] || alias_after_create_default
fi
}
alias_list() {
typeset item
case "${alias_name}" in
(names)
cat - # just show it
;;
(*)
while
read item
do
echo "$item => $("$rvm_scripts_path"/db "$rvm_path/config/alias" "$item")"
done
;;
esac < <(
cd "$rvm_rubies_path"
find . -maxdepth 1 -mindepth 1 -type l | sed -e 's#.*/##'
)
}
alias_search_by_target() {
typeset item items target search
search="${alias_name}@${gemset_name}"
items=($(cd "$rvm_rubies_path" ; find . -maxdepth 1 -mindepth 1 -type l | sed -e 's#./##'))
for item in "${items[@]}"
do
target=$("$rvm_scripts_path"/db "$rvm_path/config/alias" "$(basename "$item")")
if [[ "${search}" == "${target}" ]]
then
echo "$(basename "$item")"
fi
done
}
args=($*)
action="${args[0]:-""}"
alias_name="${args[1]:-""}"
rvm_environment_identifier="${args[2]:-""}"
args="$(echo ${args[@]:3})" # Strip trailing / leading / extra spacing.
result=0
if [[ ! -f "$rvm_path/config/alias" ]] ; then touch "$rvm_path/config/alias" ; fi
if printf "%b" "$alias_name" | GREP_OPTIONS="" \grep "${rvm_gemset_separator:-"@"}" >/dev/null 2>&1 ; then
gemset_name="${alias_name/*${rvm_gemset_separator:-"@"}/}"
alias_name="${alias_name/${rvm_gemset_separator:-"@"}*/}"
else
gemset_name=""
fi
case "$action" in
delete|create|list|show|search_by_target)
alias_${action}
;;
help|usage)
usage
;;
*)
usage
exit 1
;;
esac
exit $?
Jump to Line
Something went wrong with that request. Please try again.