Skip to content
This repository
tag: 1.0.1
Fetching contributors…

Cannot retrieve contributors at this time

executable file 107 lines (92 sloc) 3.065 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
#!/usr/bin/env bash

add(){
  token="$1"
  eval "${token}_flag=1" ; shift
if [[ ! -z "$format" ]] ; then
    format="${format}-\$${token}"
  else
    format="\$${token}"
  fi
}

rvm_gemset_separator=${rvm_gemset_separator:-"+"}
ruby=$(command -v ruby)
if [[ ! -z "$ruby" ]] && [[ ! -z "$(echo "$ruby" | awk '/rvm/{print}')" ]] ; then
  unset format
  while [[ $# -gt 0 ]] ; do
    token="$1" ; shift
case "$token" in
      i|interpreter) add "interpreter" ;;
      v|version) add "version" ;;
      p|patchlevel) add "patchlevel" ;;
      r|revision) add "revision" ;;
      a|architecture) add "architecture" ;;
      g|gemset) add "gemset" ;;
      u|unicode) add "unicode" ;;
      s|system) add "system" ;;
      -d|--no-default) no_default=1 ;;
      *) echo "Unrecognized command line option '$token' for $0" ; exit 1 ;;
    esac
  done

  if [[ -z "$format" ]] ; then
    add "interpreter"
    add "version"
    add "patchlevel"
    add "gemset"
  fi

  ruby_string=$(dirname "$ruby" | xargs dirname | xargs basename)

  # Dont' display anything if no default flag was provided and we're using the default ruby
  if [[ -n "$no_default" && "$(rvm tools identifier)" = "$(rvm alias show default)" ]]; then
exit 0
  fi

  if [[ ! -z "$interpreter_flag" ]] || [[ ! -z "$unicode_flag" ]] ; then
    interpreter="$(echo $ruby_string | awk -F'-' '{print $1}')"
  fi

  if [[ ! -z "$version_flag" ]] || [[ ! -z "$unicode_flag" ]] ; then
    version="$(echo $ruby_string | awk -F'-' '{print $2}')"
  fi

  if [[ ! -z "$patchlevel_flag" ]] ; then
    patchlevel=$(echo $ruby_string | awk -F'-' '{print $3}')
  fi

  if [[ ! -z "$architecture_flag" ]] ; then
    architecture="$(echo "$(ruby -v)" | sed 's/^.*\[//' | sed 's/\].*$//')"
  fi

  if [[ ! -z "$gemset_flag" ]] ; then
    gemset="$(echo $GEM_HOME | awk -F${rvm_gemset_separator} '{print $2}')"
    if [[ ! -z "$gemset" ]] ; then gemset="${rvm_gemset_separator}$gemset" ; fi
  fi

  if [[ ! -z "$unicode_flag" ]] ; then
    case "$interpreter" in
      jruby) unicode="☯" ;;
      rbx) unicode="☃" ;;
      ree) unicode="✈" ;;
      macruby) unicode="⌘" ;;
      maglev) unicode="㎖" ;;
      ironruby) unicode="♭" ;;
      mput) unicode="⎈" ;;
      system) unicode="➆" ;;
      ruby)
        case "$version" in
          1.8.6) unicode="❻" ;;
          1.8.7) unicode="❼" ;;
          1.9.1) unicode="❶" ;;
          1.9.2) unicode="❷" ;;
          *) unicode="♢" ;;
        esac ;;
      *) unicode="♢" ;;
    esac

    if [[ ! -z "$(echo $ruby_string | awk '/-head/')" ]] ; then
      unicode="${unicode}〠"
    fi
  fi
  
  command="prompt=\"$format\""
  eval "$command"
  echo "$prompt" | sed -e 's#^[[:space:]]*-*##g' -e 's#--*#-#g' -e 's#-*[[:space:]]*$##' -e 's#-'${rvm_gemset_separator}'#'${rvm_gemset_separator}'#'
  
else
  while [[ $# -gt 0 ]] ; do
    token="$1" ; shift
case "$token" in
      s|system) echo "system" ;;
    esac
  done
fi

exit 0
Something went wrong with that request. Please try again.