#!/usr/bin/env bash default_flag="$rvm_default_flag" # Prevent it from recursing. unset rvm_default_flag rvm_wrapper_name source "$rvm_scripts_path/base" full_binary_name() { echo "$binary_name" | __rvm_strip } wrap() { \mkdir -p "$(dirname "$file_name")" \rm -f "$file_name" echo "#!/usr/bin/env sh" > "$file_name" echo "if [ -s \"${rvm_environments_path}/${environment_identifier}\" ] ; then" >> "$file_name" echo " . \"${rvm_environments_path}/${environment_identifier}\"" >> "$file_name" echo " exec $binary_name \"\$@\"" >> "$file_name" echo "else" >> $file_name echo " echo \"ERROR: Missing RVM environment file: '${rvm_environments_path}/${environment_identifier}'\"" >> $file_name echo " exit 1" >> $file_name echo "fi" >> $file_name if [[ -f $file_name ]] ; then chmod +x $file_name ; 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_scripts_path/log "error" "Binary '$binary_name' not found in path." return 1 fi } usage() { printf "Usage: 'rvm wrapper [ruby_string] [wrapper_prefix] [binary[ binary[ ...]]]'\n" printf " Where binary defaults to ruby, gem, rake, irb, rdoc, ri, testrb\n" printf " For more information, see 'rvm help wrapper'\n" } # Empty ruby string: show usage and exit. if [[ -z "$1" ]]; then usage exit 1 fi ruby_string="$1"; shift override_check=0 prefix="$1" [[ "$#" -gt 0 ]] && shift binaries="$(echo "$@" | __rvm_strip)" # Default the list of binaries to those we use regularily. if [[ -z "$binaries" ]] ; 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_wrappers_path}/${environment_identifier}/${binary_name}" 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" \rm -rf "$destination" ln -nsf "$file_name" "$destination" fi; unset destination else symlink_binary fi ; unset file_name done exit $?