Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 102 lines (87 sloc) 2.804 kb
#!/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" ;;
*) 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)
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#^\s*-*##g' -e 's#--*#-#g' -e 's#-*\s*$##' -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
Jump to Line
Something went wrong with that request. Please try again.