#!/usr/bin/env bash

args=()
while [[ $# -gt 0 ]] ; do
  token="${1}" ; shift

  case "${token}" in
    --trace)
      export PS4="+ \${BASH_SOURCE##\${rvm_path:-}} : \${FUNCNAME[0]:+\${FUNCNAME[0]}()}  \${LINENO} > "
      set -o xtrace
      shift
      ;;

    --verbose)
      set -o verbose
      shift
      ;;
  *)
    args=("${args[@]}" "$token")
    ;;
  esac
done

command="sudo /usr/bin/env PATH='$PATH'"

[[ -n "${GEM_HOME:-}" ]] && command="${command} GEM_HOME='$GEM_HOME' "
[[ -n "${GEM_PATH:-}" ]] && command="${command} GEM_PATH='$GEM_PATH' "

command="${command} ${args[@]}"

eval "${command}"
