#!/usr/bin/env bash unset rvm_default_flag rvm_wrapper_name source "$rvm_scripts_path"/base alias_conflicts_with_ruby() { # If default exists, we should return true. [[ "$1" == "default" && ! -L "$rvm_rubies_path/default" ]] && return 1 # Open for suggestions to a better way of doing this... alias_check_result="$( \. \"$rvm_scripts_path/initialize\" \. \"$rvm_scripts_path/selector\" export rvm_ruby_string=\"$1\" __rvm_ruby_string > /dev/null 2>&1 echo "$?" )" if [[ "0" == "$alias_check_result" ]]; then "$rvm_scripts_path"/log "error" "You are attempted to create an alias called '$1', which is recognized as a rvm ruby." return 0 fi return 1 unset alias_check_result } 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 if [[ -n "$gemset_name" ]] ; then printf "${expanded_alias_name}${rvm_gemset_separator}${gemset_name}" else printf "$expanded_alias_name" fi 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 alias_conflicts_with_ruby "$alias_name"; then # Force it to an empty alias name to trigger the usage. alias_name="" fi 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" if [[ -z "$rvm_alias_expanded" ]]; then rvm_expanding_aliases=1 __rvm_become unset rvm_expanding_aliases else rvm_ruby_string="$rvm_environment_identifier" fi 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; unset item } action="$1" alias_name="$2" rvm_environment_identifier="$3" if [[ ! -f "$rvm_config_path/alias" ]] ; then \touch "$rvm_config_path/alias" ; fi if printf "$alias_name" | \grep -q "$rvm_gemset_separator" ; then gemset_name="${alias_name/*${rvm_gemset_separator}/}" alias_name="${alias_name/${rvm_gemset_separator}*/}" 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