Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

executable file 97 lines (84 sloc) 2.606 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:-"+"}
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" ;;
g|gemset) add "gemset" ;;
u|unicode) unicode_flag=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 "$(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
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
# TODO: Architecture
# TODO: gemset
echo $unicode
else
command="prompt=\"$format\""
eval "$command"
echo "$prompt" | sed 's#-\s*$##' | sed 's#-'${rvm_gemset_separator}'#'${rvm_gemset_separator}'#'
fi
else
echo "system"
fi
exit 0
Jump to Line
Something went wrong with that request. Please try again.