Working with Ruby
Hi, I am Jan. This is my old Ruby blog. I still post about Ruby, but I now do it on You should also install Irbtools to improve your IRB.

RubyBuntu -3- Be one with your command line!

Most Ruby programmers know: Many things can be done in much less time on the command line. To become more productive, you should take the 10 minutes to configure some basic settings.

Tweak your terminal

Why use complicated shortcuts for often used functionality? Adjust them to your needs at Edit/Keyboard Shortcuts…. Here are my recommendations:

Action Shortcut Key
New Tab Ctrl+Return
New Window Ctrl+Alt+Return
Move Tab to the Left Ctrl+Shift+Left
Move Tab to the Right Ctrl+Shift+Right
Switch to Next Tab Ctrl+Right
Switch to Previous Tab Ctrl+Left

After that, go to Edit/Profile Preferences and set some nice colors. I like orange on black with the Tango theme and a little bit transparency. Other useful settings include increasing the scrollback lines and hiding the menubar.

More convenience

Do yourself a faviour by maintaining shell aliases. Just add some lines to your ~/.bashrc or ~/.bash_aliases with this syntax:

alias rs='script/server'
alias rsp='script/server production'
alias ai='sudo apt-get install'
alias sth='some other --command' ...

Another thing, that really makes live easier when using the console, is the Tab key and its auto completion… So why don’t use it for rake? There is a handy rake auto completion available in the ubuntu-on-rails ppa repository. You can add the ppa and install the completion with these commands:

sudo add-apt-repository ppa:ubuntu-on-rails
sudo apt-get update
sudo apt-get install rake-completion

Interactive Ruby

Now you already have a friendly console environment. But there are still things to improve about the Ruby programmer’s favourite console: irb.

Sometimes you get complex return values, where it might be a little bit complicated to get the essence of the return value. But it can be simplified by two very nice gems: wirble and hirb.

wirble makes your irb sessions colorful (colors are great!). hirb, however, lets you view many instances of big objects in a nice table – perfect for Active Record models!

sudo gem install wirble hirb

You can both auto-activate them for each irb session (and activate simple indention) by adding the following lines to your ~/.irbrc file:

%w|rubygems wirble hirb|.each do|lib|
    require lib
  rescue LoadError => err
    warn "Couldn't load an irb gem: #{err}"

# wirble (colors)

# hirb (active record)

# IRB Options
IRB.conf[:AUTO_INDENT] = true

This is a pretty basic irb. To further tweakt it, see this future article.

Two more hints on git

If you are using the git version control system, the first thing you should do is activating the colors:

git config --global color.ui true

Another cool and useful enhancement is showing your git branch at the prompt. Simply add this script to your ~/.bashrc (based on 1, 2, 3):

# show branch and dirty status,,
function parse_git_dirty {
  [[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "⚡"
function parse_git_branch {
  local branch=$(__git_ps1 "%s")
  [[ $branch ]] && echo "[$branch$(parse_git_dirty)]"
export PS1='\u@\h \[\033[1;33m\]\w\[\033[0m\]$(parse_git_branch)$ '

It also adds a flash that indicates changes in your working directory.


The next step is about setting up the most important tool for developing: gedit!

Creative Commons License

Anonymous | September 30, 2010

re: "Tweak your terminal" - check out Terminator (in the Lucid repos), a multi-tabbed tiling wrapper for Gnome Terminal with a rich set of key bindings for splitting and resizing tiles, typing simultaneously into all panes, etc.

sudo apt-get install terminator

thecatwasnot | December 19, 2010

Favorite new toy is screeninator, launches a screen session, preloads windows and makes it all look pretty.