#!/usr/bin/env bash default_flag="$rvm_default_flag" rvm_bin_path="${rvm_bin_path:-"$rvm_path/bin"}" # Prevent recursion unset rvm_default_flag rvm_wrapper_name prefix source "$rvm_path/scripts/base" 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' " } 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" fi printf "#!/usr/bin/env bash if [[ -s \"$path/environments/${environment_identifier}\" ]] ; then \\. \"$path/environments/${environment_identifier}\" exec $binary_name \"\$@\" else echo \"ERROR: Missing RVM environment file: '$path/environments/${environment_identifier}'\" >&2 exit 1 fi " > "$file_name" if [[ -f "$file_name" ]] ; then chmod +x "$file_name" fi return 0 else "$rvm_path/scripts/log" "error" \ "wrap() : file_name unkown variable for wrap()." return 1 fi } 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() { # 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." return 1 fi } # Empty ruby string: show usage and exit. if [[ "$#" -eq 0 ]] ; then usage exit 1 else ruby_string="${1:-""}" shift fi if [[ "$#" -gt 0 ]] ; then prefix="${1:-""}" shift fi binaries=($(echo "$@")) 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) fi # Use the correct ruby. __rvm_become "$ruby_string" __rvm_ensure_has_environment_files environment_identifier="$(__rvm_environment_identifier)" # 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}" if [[ ${rvm_default_flag:-0} -gt 0 ]] ; then prefix="default" fi if [[ -z "$prefix" ]] ; then override_check=1 wrap_binary # Symlink it into place. if [[ -f "$file_name" ]]; then if [[ "$binary_name" == "ruby" ]] ; then destination="$rvm_bin_path/$environment_identifier" else destination="$rvm_bin_path/${binary_name}-${environment_identifier}" fi rm -rf "$destination" ln -nsf "$file_name" "$destination" fi; unset destination elif [[ "$prefix" == "--no-prefix" ]]; then override_check=1 wrap_binary if [[ -f "$file_name" ]]; then destination="$rvm_bin_path/$binary_name" if [[ -s "$destination" ]] ; then rm -rf "$destination" fi ln -nsf "$file_name" "$destination" fi else symlink_binary fi done exit $?