Opening multiple command prompts with multiple commands in each, using Ubuntu 10.04

Before getting all stinky in development mode, it's usually necessary to open a number of different terminals:  One for the server, another for Spork, another for autotest, another for for Compass, and another to tail my development log.  Prior to setting this up I'd just do shift+ctrl+t to open a new tab followed by the appropriate command in each terminal to begin each process, but as an exercise in learning more about Bash and the terminal I decided to try to automate some of it.  I'm sure there are a number of better ways to automate this process, but to paraphrase the rifleman's creed:  This one is mine.  It should work fine for any flavor of Ubuntu, though my particular version is 10.04.    

The first thing to do is open up your terminal with a good set of default tabs.  To open the tabs I need and get the processes I want started, I used:

$ gnome-terminal --tab -e "bash -c 'rails server'" --tab -e "bash -c 'spork'" --tab -e "bash -c 'autotest'" --tab -e "bash -c 'compass watch'" --tab -e 'tail -f log/development.log'

You should be able to cut and paste this directly if you use the same tabs, but it may make more sense in your own implementation to try just a couple of these commands at first.  The next step is to create a file to store this tab configuration in.  I'm not sure if it was the wisest choice, by I named my configuration file "railstabs," and put it into the root directory of a Rails 3 application I'm building called Skygodlin.  

Now this may not make a whole lot of sense, but you will want to close all of your older terminals at this point.  Just trust me on this.  Leave only the terminal with the needed tabs open.  And then open a new tab in that terminal and use this command to save your configuration:

$ gnome-terminal --save-config=/home/frederick/Dorpbox/skygodlin/railstabs
You'll want to check and see what that file looks like.  Here's mine:
#Written by GNOME Terminal 2.30.2

[GNOME Terminal Configuration]
Version=1
CompatVersion=1
FactoryEnabled=true
Windows=Window0;

[Window0]
MenubarVisible=true
Role=gnome-terminal-window-2754--618914462-1298626727
ActiveTerminal=Terminal0x83fea18
Geometry=80x24+0+239
Terminals=Terminal0x8371800;Terminal0x838eda0;Terminal0x837bc00;Terminal0x83c1468;Terminal0x83fea18;

[Terminal0x8371800]
ProfileID=Default
Command='bash' '-c' 'autotest'
WorkingDirectory=/home/frederick/Dropbox/skygodlin
Zoom=1
Width=80
Height=24

[Terminal0x838eda0]
ProfileID=Default
Command='bash' '-c' 'compass watch'
WorkingDirectory=/home/frederick/Dropbox/skygodlin
Zoom=1
Width=80
Height=24

[Terminal0x837bc00]
ProfileID=Default
Command='tail' '-f' 'log/development.log'
WorkingDirectory=/home/frederick/Dropbox/skygodlin
Zoom=1
Width=80
Height=24

[Terminal0x83c1468]
ProfileID=Default
Command='bash' '-c' 'spork'
WorkingDirectory=/home/frederick/Dropbox/skygodlin
Zoom=1
Width=80
Height=24

[Terminal0x83fea18]
ProfileID=Default
Command='bash' '-c' 'rails server'
WorkingDirectory=/home/frederick/Dropbox/skygodlin
Zoom=1
Width=80
Height=24
Once you've confirmed your own configuration file is a reasonable facsimile of the above, it's time to see if you can open it up again.  First, close up all your old terminals but one, and use:
$ gnome-terminal --load-config=/home/frederick/Dorpbox/skygodlin/railstabs
And boom!  Just like that, you should get a terminal with all those tabs opening up and, if you're using Autotest, a bunch of green mothafuckin smiley faces.  
Now of course, as you have probably noticed, the above command is unwieldy.  So let's see if we can make it a bit simpler by harnessing the power of the Bourne again Shell.  I can't say what's in your .bashrc file, but mine had the following comments:
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

# if [ -f ~/.bash_aliases ]; then
#     . ~/.bash_aliases
# fi
And so I took their suggestion and uncommented three of the above lines, like so:
# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi
And then created a ~/.bash_aliases file with the following code:
alias gemi='gem install'
alias rs='rails server'
alias skygodlin='gnome-terminal --load-config=/home/frederick/Dropbox/skygodlin/railstabs'
And now when I want to work on Skygodlin, I just type this at the command prompt:
$ skygodlin
And everything works as it should.  Please do let me know if you have suggestions for improvement, either in my method, or in how I've explained it.  

Growl style images for autotest-notification using Ubuntu 10.04

For anyone working through Michael Hartl's Railstutorial using Rails 3, and Ubuntu 10.04, and who wants to use autotest-notification, these instructions should work.  They are essentially a copy of the installation instructions put up by Carlos Brando, except tailored to make the notifications look more like OSX's Growl:

1) Install libnotify:

sudo apt-get install libnotify-bin
2) Then install autotest-notification to your global gemset for the ruby interpreter you're using.  In the example below, I'm using 1.8.7 but you could just as easily be using 1.9.2:

rvm use 1.8.7@global
gem install autotest-notification
an-install

3) Now switch back to your default ruby interpreter and gemset: 

rvm default
or, if you haven't set a default interpreter and gemset, you can first create a gemset using:

rvm gemset create railstutorial
and then set those defaults using:

rvm use 1.8.7@railstutorial --default
4) Now navigate to the image directory where your gems are stored.  Mine is here:
~/.rvm/gems/ruby-1.8.7-p299@contractango/gems/autotest-notification-2.2.1/images
and replace the stock images with images below:

(download)

Also, if these instructions are unclear to you please do let me know in the comments below, so that I can clarify them.  And since the instructions may change as the gem matures, if all else fails, I refer you again to Carlos Brando's instructions, which should work just fine.

 

UPDATE:  These steps work fine for Ubuntu 10.10, but not for 11.04 Natty Narwhal unless you are using Ruby 1.8.7.  Using 1.9.2-p180 or 1.9.2-p136 with Natty Narwhal causes autotest to hang.  Here's a copy of the bug report.  For now, you should either stay with Ubuntu 10.04 or Ubuntu 10.10 if you want to use Ruby 1.9.2, or be content with using 1.8.7 with 11.04.  Also, please let me know in the comments if you are able to find a work around.  Thanks!

UPDATE II: If you're having trouble with autotest hanging on Natty Narwhal, consider updating your linux kernel using the following instructions, as I did:  http://ubuntuguide.net/ubuntu-11-04-upgrade-linux-kernel-to-2-6-39-0

 

Michael Hartl's Rails Tutorial with Rails 3 Beta. Part 1: Installing Gmate, Git, and Ruby Version Manager

These is part one of my notes on running through Michael Hartl's most excellent and aptly titled Ruby on Rails Tutorial, using Rails 3 Beta.  I'm using Ubuntu 10.04 Lucid Lynx.  Hope it helps get you going.

1) Vim is forever yes, I know.  But the learning curve was too steep for me.  So I chose the Gmate extension for Gedit, because it lets me open files with the "mate" command just like TextMate.  Instructions here.  
 
2) Install Git now, because it's required to install Ruby Version Manager.
 
a) Take a look at Scott Chacon's book "Pro Git" for guidance on installing Git:  http://progit.org/book/ch1-4.html.  I saw Scott give a talk at a Rails meetup a while back and he's a good dude.  He has a number of different installation methods, but I chose the easiest, which worked fine:
:~$ sudo apt-get install git-core
b) You'll get a chance to configure Git in Chapter 1 of RailsTutorial, so don't mess with that stuff till then.
 
3) Ruby Version Manager pretty slick, once you get it set up.  Unfortunately, getting it set up is difficult, or at least was for me.  But then I'm just a dumb former paratrooper and college dropout.

a) Installation page for RVM is here.  I suggest reading through the installation instructions several times before doing anything.  

c) Editing my profiles, according to the instructions, was hard for me.  Looking back, I think you just have to edit your ~/.bashrc file, but I also edited my /etc/profile file and created a file called ~/bash_profile just in case.  The contents of all three of these files are available below.  I'd recommend against cutting & pasting; rather, edit you should your own files using these as a starting point:

  • A gist of my ~/.bashrc file is here -- 
  • A gist of my ~/.bash_profile is here 
  • A gist of my /etc/profile is here -- 

d) Once RVM is installed, you can install as many different Ruby versions as you like.  

:~$ rvm install 1.8.7

 

:~$ rvm install 1.9.1

 

e) Then select a default Ruby:

 

:~$ rvm --default 1.9.1

f) When you run rvm list, it should look something like:

:~$ rvm list

rvm Rubies

   ruby-1.8.7-p249 [ i386 ]

=> ruby-1.9.1-p378 [ i386 ]

   ruby-1.9.2-head [ i386 ]

Default Ruby (for new shells)

   ruby-1.9.1-p378 [ i386 ]

g) Now switch back to Ruby 1.8.7 and install Rails 2.3.5:

:~$ rvm use 1.8.7

Using ruby 1.8.7 p249

:~$ gem install rails 2.3.5

h) Now switch to Ruby 1.9.1 and install Rails 3 Beta:

:~$ rvm use 1.9.1

Using ruby 1.9.1 p378

:~$ gem install rails --pre

i) Now confirm that you have two different versions of ruby and of rails:

:~$ rvm use 1.8.7

Using ruby 1.8.7 p249

:~$ rails -v

Rails 2.3.5

:~$ rvm use 1.9.1

Using ruby 1.9.1 p378

:~$ rails -v

Rails 3.0.0.beta3

If you're having trouble with this stuff, jump onto the RVM channel and ask for help.  RVM's creator, Wayne Seguin, hangs out there but even if he isn't, there may be someone else -- as was the case when I got on last night and a kindly fellow named Rohit, who has his own instructions for setting up RVM and Rails 3 here, was able to get me squared away.  Thanks Rohit.