Skip to content
This repository
tag: 1.6.14
Fetching contributors…

Cannot retrieve contributors at this time

executable file 227 lines (119 sloc) 3.566 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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227
#!/usr/bin/env bash

add()
{

  token=${1:-""}

  eval "${token}_flag=1" ; shift

if [[ -n "$format" ]] ; then

    if [[ ${previous_is_format_var:-0} = 1 ]] ; then

      format="${format}-\$${token}"

    else

      format="${format}\$${token}"

    fi

  else

    format="\$${token}"

  fi

  previous_is_format_var=1

  return 0
}

add_raw_token()
{
  previous_is_format_var=0

  token=${1:-""}

  format="${format:-""}${token}"

  return 0
}

rvm_gemset_separator="${rvm_gemset_separator:-"@"}"

ruby=$(command -v ruby)

if [[ -n "$ruby" && -n "$(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 ;;

      *) add_raw_token "$token" ;;

    esac

  done

  if [[ -z "${format:-""}" ]] ; then

    for default in interpreter version patchlevel gemset ; do

      add "$default"

    done

  fi

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

  if [[ -n "$no_default" ]]; then

    # Do not display anything if no default flag was provided
    # and we are using the default ruby

    # Only people who explicitely ask for this will have the
    # slight performance penalty associated.

    if [[ "$(rvm tools identifier)" = "$(rvm alias show default)" ]] ; then

      exit 0

    fi

  fi

  strings=(${ruby_string//-/ })

  if [[ ${interpreter_flag:-0} -gt 0 || -n "$unicode_flag" ]] ; then

    interpreter=${strings[0]}

  fi

  if [[ ${version_flag:-0} -gt 0 || -n "$unicode_flag" ]] ; then

    version=${strings[1]}

  fi

  if [[ ${#strings[@]} -gt 2 ]] ; then

    if [[ ${patchlevel_flag:-0} -gt 0 ]] ; then

      patchlevel=${strings[2]}

    fi

  fi

  if [[ ${architecture_flag:-0} -gt 0 ]] ; then

    architecture="$(echo "$(ruby -v)" | sed 's/^.*\[//' | sed 's/\].*$//')"

  fi

  if [[ ${gemset_flag:-0} -gt 0 ]] ; then

    case "${GEM_HOME:-""}" in

      *${rvm_gemset_separator:-"@"}*)

        gemset="${rvm_gemset_separator:-"@"}${GEM_HOME/*${rvm_gemset_separator:-"@"}/}"

        ;;

    esac

  fi

  if [[ ${unicode_flag:-0} -gt 0 ]] ; then

    case "$interpreter" in

      jruby) unicode="☯" ;;

      rbx) unicode="☃" ;;

      ree) unicode="✈" ;;

      macruby) unicode="⌘" ;;

      maglev) unicode="㎖" ;;

      ironruby) unicode="♭" ;;

      system) unicode="➆" ;;

      goruby) 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 echo "$ruby_string" | \grep '-head' >/dev/null 2>&1 ; then

      unicode="${unicode}〠"

    fi

  fi

  eval "prompt=\"$format\""

  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.