home icon contact icon rss icon last FM icon facebook icon LinkedIn icon Delicious icon twitter icon

RVM tips - Tell me my ruby version !

Now that Rails 3 is out, I'm starting to use it on recent application. But I also have some work to do on older applications from time to time.

The first annoying thing is that older applictions are built for Ruby 1.8.6 and Rails 3 works with Ruby 1.9.2. The other thing is that the rails command is radicaly different from Rails 2.3.8 to Rails 3.

Using RVM, I'm able to easily switch from one Ruby version to another and from one gems configuration to another. And this depending on the shell I am on.

The counterpart of this is that I'm very confused and never know on which configuration my shell is currently. So I needed a clear way to know it. It would be great if the prompt can tell it to me. Here is how to do that with bash :

# Copy this in ~/.bashrc
    __ruby_ps1 ()
        local g=`ruby -v | cut -d' ' -f2`

        if [ -n "$1" ]; then
            printf "$1" "${g}"
            printf "(%s)" "${g}"

    export PS1='\u@\h$(__ruby_ps1):\w\$ '

Claire la soeurette dit

le Mercredi 24 novembre 2010 à 17h05

Ça n'a rien a voir, mais ya une (grosse?) faute d'orthographe qui fait tache dans la page "A Propos". Dans le dernier paragraphe, "Il est fait pour fonctionné" Voila :)

Sunny dit

le Mardi 21 décembre 2010 à 09h09

Yabon ! Je rajoute ça à ma ceinture de gadgets à activer de temps en temps (ou automatiquement quand on est dans un dossier Rails ça serait une idée).

Ça n'a rien a voir non plus mais le commentaire d'"Exchange" est un gros spam poilu.