Skip to content
This repository
tag: 0.1.9
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 54 lines (46 sloc) 1.37 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
#!/usr/bin/env bash

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

if [[ ! -z "$(which ruby 2>/dev/null | 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" ;;
      *) echo "Unrecognized command line option '$token' for $0" ; exit 1 ;;
    esac
done

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

ruby_string=$(dirname "$(which ruby 2>/dev/null)" | xargs dirname | xargs basename)
  if [[ ! -z "$interpreter_flag" ]] ; then
interpreter="$(echo $ruby_string | awk -F'-' '{print $1}')"
  fi
if [[ ! -z "$version_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

command="prompt=\"$format\""
  eval "$command"
  echo "${prompt/-]/]}"
fi

exit 0

Something went wrong with that request. Please try again.