hugopl/devblog

21 May 2014

Display Ruby version on prompt

The problem: I have multiple versions of Ruby installed and want to be sure about what version is the default on a terminal session.

Solution: Display the version on prompt!

I already do it for git branches, to show Ruby version is even simpler, on your .bashrc

RUBYVERSION='$(ruby --version | cut -f2 -d\ )'
PS1="\u \w [${RUBYVERSION}] \$ "

Of course you will change the PS1 to fit your needs with colors, etc… or your prompt will be pretty gray and ugly, BTW here is mine:

RUBYVERSION='$(ruby --version | cut -f2 -d\ )'
GITPS1='$(__git_ps1 "(%s)")'
PS1="\033[01;32m\u\033[0m \w \033[31m${GITPS1}\033[0m \033[35m[${RUBYVERSION}]\033[0m\n\$ "
comments powered by Disqus