#!/usr/bin/env bash unset rvm_default_flag rvm_wrapper_name if [[ ! -z "$rvm_trace_flag" ]] ; then set -x ; export rvm_trace_flag ; fi trap "if [[ -d $rvm_tmp_path/ ]] && [[ -f $rvm_tmp_path/$$ ]] ; then rm -f $rvm_tmp_path/$$ > /dev/null 2>&1 ; fi ; exit" 0 1 2 3 15 source $rvm_scripts_path/initialize source $rvm_scripts_path/utility source $rvm_scripts_path/selector show_alias() { if [[ -z "$alias_name" ]]; then $rvm_scripts_path/log "error" "usage: 'rvm alias show [alias_name]'" result=1 return fi expanded_alias_name="$($rvm_scripts_path/db "$rvm_config_path/alias" "$alias_name")" if [[ -z "$expanded_alias_name" ]]; then $rvm_scripts_path/log "error" "Unknown alias name: '$alias_name'" result=1 else result=0 echo "$expanded_alias_name" fi unset expanded_alias_name } delete_alias() { echo "Deleting alias: $alias_name" for link in "$rvm_rubies_path/$alias_name" ; do if [[ -L "$link" ]] ; then rm -f $link ; fi done $rvm_scripts_path/db "$rvm_config_path/alias" "$alias_name" "delete" } create_alias() { if [[ -z "$rvm_environment_identifier" ]] || [[ -z "$alias_name" ]] ; then $rvm_scripts_path/log "error" "usage: 'rvm alias [alias_name] [ruby_string]'" result=1 else if [[ -z "$rvm_alias" ]] ; then rvm_ruby_string="$rvm_environment_identifier" rvm_expanding_aliases=1 __rvm_become unset rvm_expanding_aliases if [[ -z "$rvm_ruby_string" ]]; then $rvm_scripts_path/log "error" "unknown ruby string specified" result=1 return fi final_environment_identifier="$(__rvm_environment_identifier)" $rvm_scripts_path/log "info" "Creating alias $alias_name for $final_environment_identifier." ln -nfs "$rvm_rubies_path/$rvm_ruby_string" "$rvm_rubies_path/$alias_name" $rvm_scripts_path/log "info" "Recording alias $alias_name for $final_environment_identifier." $rvm_scripts_path/db "$rvm_config_path/alias" "$alias_name" "$final_environment_identifier" else if [[ -d "$rvm_rubies_path/$alias_name" ]] ; then $rvm_scripts_path/log "error" "$rvm_rubies_path/$alias_name is taken and is *not* able to be an alias name." result=1 else $rvm_scripts_path/log "error" "$rvm_rubies_path/$alias_name is already aliased." result=1 fi fi fi } alias_list() { for item in $rvm_rubies_path/* ; do if [[ -L "$item" ]] ; then echo "$(basename $item) => $($rvm_scripts_path/db "$rvm_config_path/alias" "$(basename "$item")")" fi done } action="$1" alias_name="$2" rvm_environment_identifier="$3" if [[ ! -f "$rvm_config_path/alias" ]] ; then touch "$rvm_config_path/alias" ; fi if [[ ! -z "$alias_name" ]] ; then rvm_alias="$($rvm_scripts_path/db "$rvm_config_path/alias" "$alias_name")" fi # CLI API: # rvm alias create [alias_name] [ruby] # rvm alias delete [alias_name] # rvm alias show [alias_name] # rvm alias list if [[ "$action" = "delete" ]] ; then delete_alias elif [[ "$action" = "create" ]] ; then create_alias elif [[ "$action" = "list" ]] ; then alias_list elif [[ "$action" = "show" ]]; then show_alias else $rvm_scripts_path/log "error" "usage: 'rvm alias [action] [arguments]" fi unset action alias_name rvm_ruby_string rvm_environment_identifier final_environment_identifier exit $result