#!/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. wrap_binary # Note, now forcing this every time to force clean. # Then symlink it into place. rm -f "${rvm_bin_path}/${prefix}_${binary_name}" ln -fs "$file_name" "${rvm_bin_path}/${prefix}_${binary_name}" } wrap_binary() { # Iff the command is found in the path. if command -v $binary_name > /dev/null; then wrap else $rvm_scripts_path/log "error" "Binary '$binary_name' not found in path." 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 prefix="$1" if [[ -n "$1" ]]; then shift; fi binaries="$(echo "$@" | __rvm_strip)" if [[ 'system' == '$ruby_string' ]]; then $rvm_scripts_path/log "error" "Wrapper can't be called with system rubies - sorry!" exit 1 fi # 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_enviroment_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 wrap_binary # Symlink it into place. if [[ "$binary_name" == "ruby" ]] ; then rm -f "${rvm_bin_path}/${environment_identifier}" ln -nsf "${file_name}" "${rvm_bin_path}/${environment_identifier}" else rm -f "${rvm_bin_path}/${binary_name}-${environment_identifier}" ln -nsf "${file_name}" "${rvm_bin_path}/${binary_name}-${environment_identifier}" fi if [[ "root" = "$(whoami)" ]] && [[ "${default_flag}" = 1 ]] ; then rm -f "${rvm_bin_path}/${binary_name}" ln -nsf "${file_name}" "${rvm_bin_path}/${binary_name}" fi else symlink_binary fi ; unset file_name done exit $?