Thursday, November 3, 2011

Spruce up your Terminal

It's very annoying when mouse doesn't work inside Vim in Mac's Terminal and when Cmd + 1-9 doesn't work while switching tabs. With some googling here are simple steps for making these things work.

The first thing you need to install in SIMBL - (SIMple Bundle Loader) - pronounced like "symbol" or "cymbal" - enables hacks and plugins. Download it from Unzip it and use the .pkg installer.

Next step is to get the required plugins. Most of the plugins come with installer but it's easy to do it yourself.  Plugins can be copied to /Library/Application Support/SIMBL/Plugins for all users or ~/Library/Application Support/SIMBL/Plugins for just your account.

Using MouseTerm Plugin -
MouseTerm is a SIMBL plugin for Mac OS X's that passes mouse events to the terminal, allowing you to use mouse shortcuts within applications that support them.
Download .dmg file from
Run Install and restart Terminal app.  To enable mouse for all events inside vim, add this to your .vimrc file
if has("mouse")
   set mouse = a
To check other information and possible values run :help inside vim.

Switching between tabs using cmd + 1-9
cmd + 1-9 lets you switch between different windows, but if you like to work with multiple tabs instead, you can change the behavior of this key combination using TerminalTabSwitching plugin.
Download it here.
Extract it in ~/Library/Application Support/SIMBL/Plugins

Changing bash prompt - 
To customize your bash prompt, you can refer to this post

Adding colors to bash prompt - 
Good explanation on how to add colors to bash prompt can be found here.

Adding git branch to bash prompt - 
This is really helpful, if you work with many branches in git. I have covered this in my earlier post.

Just a quick note, mouse events and tab switching works by default in iTerm 3 and it also supports many more features such as vertical / horizontal splits etc. Give it a shot. 

Wednesday, November 2, 2011

How to install Ruby on Rails on mac

Update: There is an updated version of this article at How to Install Ruby on Rails on Mac - Updated

This is first tutorial in ruby on rails series. This post will show you the exact steps you need to follow to get Ruby on Rails up and running on your Mac.

If you are new to Terminal and Mac os X in general; you will find this helpful.

Since mac gives us shell access, we can take advantage of Linux goodies. The most useful and recommended tool is rvm. It stands for Ruby Version Manager. It's a command-line tool which allows you to easily install, manage, and work with multiple ruby environments including sets of gems. With new versions of ruby getting released periodically, it's nice to have a version manager.

OS X comes with ruby installation by default. Check the version of installed ruby -
 ruby -v
Most likely, you will see ruby 1.8.7 pre-installed for you. Now it's time to upgrade to either 1.9.2 or 1.9.3.

Step 1 - git installation
rvm requires git to be installed on your system. If you already have git, skip to the next step.
git is a popular version control manager used by many open source projects including linux kernel and android. Download the appropriate installer from here
Open the .dmg file and you will find the installer package. Follow the instructions to install git.
To verify, inside Terminal type git and you should see a list of available git commands.

Step 2 - RVM installation
For GUI lovers, there is GUI version available just for Mac users. Download from here -
For rest of of us who love Terminal, follow along. It's one step process. Inside Terminal run this command -
bash < <(curl -s
It downloads rvm and installs it for you.

Step 3 - Load RVM
This step is analogous to adding rvm to your $PATH or environment variable.
Again inside Terminal,
echo ‘[[ -s "$HOME/.rvm/scripts/rvm" ]] && source “$HOME/.rvm/scripts/rvm”‘ >> ~/.bash_profile
It add rvm scripts to your bash profile so that every time you open the terminal, rvm gets loaded in the Terminal.

Step 4 - Verify RVM installation
Restart Terminal. Use cmd + Q to close the application and open it again.
Now it's time to see how rvm looks. Type rvm in Terminal and you will be greeted by a long message.

Step 5 - Download and Install xcode
xcode covers most of the dependencies for new Ruby installation. It also includes gcc compiler and other important development tools. You can download Xcode from Apple’s App Store. Search for “xcode” and click the install button.

Step 6 - Upgrade to Ruby 1.9.2
We will use 1.9.2 for this tutorial as it's the most recent stable version.
Inside Terminal,
$ rvm list known
# MRI Rubies
This is the list of all components known and managed by rvm.

We will install ruby 1.9.2.
$ rvm install 1.9.2
Next, check the installed versions by rvm using
$ rvm list
Now start using 1.9.2 by this command
$ rvm use 1.9.2

Your current ruby version is 1.9.2 but you might want to make this as your default version.
$ rvm --default 1.9.2
Check the version in another Terminal window
$ ruby -v
$ which ruby
You are almost done!

Step 7 - Install gems
Ruby gems are managed by a command line tool called 'gem' and it's preinstalled for you by rvm. You can use it to install other gems such as rails or sinatra etc.
$ gem install rails
rvm chooses gems depending on the current version of ruby and you can switch between different version by using 'rvm use' command.

Step 8 - Create Your rails project (optional)
 cd ~
 mkdir rails-apps
 cd rails-apps
 rails new hello
 cd hello
 rails s
In your browser, open localhost:3000/. You have successfully installed Ruby on Rails on mac :)

Tuesday, November 1, 2011

Using Macbook Pro like a Pro

Getting a new macbook pro at work was very exciting. I instantly fell in love with the trackpad and mouse gestures and the overall look and feel of all applications, the dockbar, the cute little animated effects. As I started setting up my development environment, I started missing my Ubuntu and Windows comfy zone.

The first shock was no home and end keys, instead a key combination. I still can't get over it. No page down and page up. And how do you refresh a page? Stop decreasing the brightness, it would help it could reload the page instead. Coming from Windows land, mac keyboard didn't feel native to me. But I promised myself to learn how to use mac like a pro. I will share some of my newly acquired wisdom here :)