#!/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) 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 "$ruby" | 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