diff --git a/.bashrc b/.bashrc index d8112b3..5eb109a 100644 --- a/.bashrc +++ b/.bashrc @@ -153,16 +153,25 @@ ps1_host='\h' . $HOME/bin/bash_vcs.sh ps1_vcs='$(__prompt_command)' -if type rvm-prompt >/dev/null 2>&1; then - ps1_ruby=' \[\e[0;34m\]$(rvm-prompt v g)\[\e[00m\]' -elif [[ -n "$RUBY_VERSION" ]]; then - ps1_ruby=' \[\e[0;34m\]$RUBY_VERSION\[\e[00m\]' -elif type ruby >/dev/null 2>&1; then - ps1_ruby=' \[\e[0;34m\]$(ruby -e "puts RUBY_VERSION")\[\e[00m\]' -else - ps1_ruby='' -fi +__prompt_ruby_version() { + if type rvm-prompt >/dev/null 2>&1; then + rvm-prompt v g + return $? + fi + + if [[ -n "$RUBY_ROOT" ]]; then + local ruby_version="$(basename "$RUBY_ROOT")" + elif type ruby > /dev/null 2>&1; then + local ruby_version="$(ruby -e "puts defined?(RUBY_ENGINE_VERSION) ? \"#{RUBY_ENGINE}-#{RUBY_ENGINE_VERSION}\" : \"ruby-#{RUBY_VERSION}\"")" + else + local ruby_version='' + fi + + ruby_version="${ruby_version#ruby-}" + echo "$ruby_version" +} +ps1_ruby=' \[\e[0;34m\]$(__prompt_ruby_version)\[\e[00m\]' # set variable identifying the chroot you work in (used in the prompt below) if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then