scripts/wrapper in rvm-1.0.11 vs scripts/wrapper in rvm-1.0.13

- old
+ new

@@ -6,43 +6,52 @@ # Prevent recursion unset rvm_default_flag rvm_wrapper_name prefix source "$rvm_path/scripts/base" -usage() { +usage() +{ printf " Usage: rvm wrapper [ruby_string] [wrapper_prefix] [binary[ binary[ ...]]] Binaries ruby, gem, rake, irb, rdoc, ri, testrb - For more information, see 'rvm help wrapper' + Notes + For more information, see 'rvm help wrapper' + + Example + + # Wrap the spec binary as 'rails3_spec' for 1.9.2@rails3 + rvm wrapper 1.9.2@rails3 rails3 spec + " } -wrap() { +wrap() +{ if [[ -n "${file_name:-""}" ]] ;then mkdir -p "$(dirname "$file_name")" rm -f "$file_name" if [[ "root" = "$USER" ]] ; then path="${rvm_path:-"/usr/local/rvm"}" else - path="$HOME/.rvm" + path="${rvm_path:-"$HOME/.rvm"}" fi printf "#!/usr/bin/env bash if [[ -s \"$path/environments/${environment_identifier}\" ]] ; then - \\. \"$path/environments/${environment_identifier}\" + source \"$path/environments/${environment_identifier}\" exec $binary_name \"\$@\" else echo \"ERROR: Missing RVM environment file: '$path/environments/${environment_identifier}'\" >&2 exit 1 fi @@ -62,53 +71,62 @@ return 1 fi } -symlink_binary() { +symlink_binary() +{ # Generate the default wrapper with the given binary name. # We first check if we can wrap the binary and if we were able to, # we then symlink it into place. if wrap_binary && [[ -f "$file_name" ]]; then rm -f "$rvm_bin_path/${prefix}_${binary_name}" ln -fs "$file_name" "$rvm_bin_path/${prefix}_${binary_name}" fi + } -wrap_binary() { +wrap_binary() +{ # We wrap when the given binary is in the path or override_check is set to one. if [[ "$override_check" = "1" ]] || command -v $binary_name > /dev/null; then wrap else - "$rvm_path/scripts/log" "error" "Binary '$binary_name' not found in path." + "$rvm_path/scripts/log" "error" "Binary '$binary_name' not found." return 1 fi + } # Empty ruby string: show usage and exit. -if [[ "$#" -eq 0 ]] ; then +if [[ $# -eq 0 ]] ; then usage exit 1 else ruby_string="${1:-""}" shift fi -if [[ "$#" -gt 0 ]] ; then +if [[ $# -gt 0 ]] ; then prefix="${1:-""}" shift fi -binaries=($(echo "$@")) +if [[ -z "$ruby_string" ]] ; then + usage + exit 1 +fi + +binaries=($@) override_check=0 # Default the list of binaries to those we use regularily. if [[ ${#binaries[@]} -eq 0 ]] ; then binaries=(ruby gem irb ri rdoc rake erb testrb) @@ -123,18 +141,22 @@ # For each binary, we want to generate the wrapper / symlink # it to the existing wrapper if needed. for binary_name in "${binaries[@]}"; do - file_name="$rvm_path/wrappers/${environment_identifier}/${binary_name}" + file_name="$rvm_path/wrappers/${environment_identifier}/${binary_name##*\/}" if [[ ${rvm_default_flag:-0} -gt 0 ]] ; then prefix="default" fi + if [[ ! -d "$rvm_bin_path" ]] ; then + mkdir -p "$rvm_bin_path" + fi + if [[ -z "$prefix" ]] ; then override_check=1 wrap_binary @@ -146,34 +168,33 @@ destination="$rvm_bin_path/$environment_identifier" else - destination="$rvm_bin_path/${binary_name}-${environment_identifier}" + destination="$rvm_bin_path/${binary_name##*\/}-${environment_identifier}" fi - rm -rf "$destination" + rm -f "$destination" ln -nsf "$file_name" "$destination" - fi; unset destination + fi + elif [[ "--no-prefix" == "$prefix" ]]; then - elif [[ "$prefix" == "--no-prefix" ]]; then - override_check=1 wrap_binary if [[ -f "$file_name" ]]; then - destination="$rvm_bin_path/$binary_name" + destination="$rvm_bin_path/${binary_name##*\/}" if [[ -s "$destination" ]] ; then - rm -rf "$destination" + rm -f "$destination" fi ln -nsf "$file_name" "$destination" fi @@ -181,10 +202,9 @@ else symlink_binary fi - done exit $?