My Secret Life as a Spaghetti Coder
home | about | contact | privacy statement
Yesterday I got sick of typing rake test and rake db:migrate and being told
You have already activated rake 0.9.2, but your Gemfile requires rake 0.8.7. Consider using bundle exec.
I know you should always run bundle exec, but my unconscious memory has not caught up with my conscious one on that aspect, so I always forget to run rake under bundle exec.

So I wondered aloud on twitter if I could just alias rake to bundle exec rake, but confine that setting to specific directories (with bash being my shell).

Turns out, it is possible with the help of another tool that Calvin Spealman pointed me towards: capn.



To successfully run the commands I've listed below, you need to have python and homebrew already installed. If you already have libyaml installed or have another way of getting it, there's no need for homebrew.

The section beginning with the line that starts out with echo and ending with -unalias rake"... creates the capn config file. It's just YAML, so if you'd rather create it with a text editor, you can surely do so. See the capn project for details on the config possibilities.

Either way, you'll want to change the paths I've used to the places you want to do the aliasing.

From the terminal, run the following commands:

curl -O http://python-distribute.org/distribute_setup.py
sudo python distribute_setup.py
sudo easy_install pip
sudo brew install libyaml
sudo easy_install -U pyyaml
sudo pip install capn
echo "
settings:
  default_type: path

hooks:
  - path: ~/workspace #change this to the path where you want to alias rake
    type: tree # if you don't want the whole tree under the path above, remove this line
    enter:
      - echo aliasing rake to 'bundle exec rake'
      - alias rake='bundle exec rake'
    exit:
      - echo unaliasing rake from 'bundle exec rake'
      - unalias rake" > ~/.capnhooks


source capn # put this line in your .bash_profile if you want capn to work when you enter the shell

# to deactivate the hooks, use: unhook

Enjoy the silence now that you don't have to hear the whining.

Hey! Why don't you make your life easier and subscribe to the full post or short blurb RSS feed? I'm so confident you'll love my smelly pasta plate wisdom that I'm offering a no-strings-attached, lifetime money back guarantee!


Comments
Leave a comment

At work we discovered that some gems or plugins would actually call rake for us, with no option to use bundle exec. So we actually patched the rake binary to boot up Bundler if it sees a Gemfile.

I really wish that all gem-provided binaries would come with Bundler-awareness.

Posted by Henning Koch on Jun 26, 2011 at 03:54 PM UTC - 5 hrs

That's a cool idea. I'd also contact the authors of those gems so they can fix their work for everyone else. =)

Posted by Sammy Larbi on Jul 06, 2011 at 06:00 AM UTC - 5 hrs

Just use the --binstubs flag to bundle and it'll stub out the right version of rake for you.

See:

http://yehudakatz.com/2011/05/30/gem-versioning-an...

Posted by Graham Randall on Sep 16, 2011 at 12:53 PM UTC - 5 hrs

@Graham - thanks for pointing that out to me. I had read the top part of that blog post before, but I guess I didn't make it down to binstubs.

Either way, this was a fun diversion for me on the day I did it.

I wonder why they didn't do binstubs by default?

Posted by Sammy Larbi on Sep 20, 2011 at 06:16 AM UTC - 5 hrs

Leave a comment

Leave this field empty
Your Name
Email (not displayed, more info?)
Website

Comment:

Subcribe to this comment thread
Remember my details
Google
Web CodeOdor.com

Me
Picture of me

Topics
.NET (19)
AI/Machine Learning (14)
Answers To 100 Interview Questions (10)
Bioinformatics (2)
Business (1)
C and C++ (6)
cfrails (22)
ColdFusion (78)
Customer Relations (15)
Databases (3)
DRY (18)
DSLs (11)
Future Tech (5)
Games (5)
Groovy/Grails (8)
Hardware (1)
IDEs (9)
Java (38)
JavaScript (4)
Linux (2)
Lisp (1)
Mac OS (4)
Management (15)
MediaServerX (1)
Miscellany (76)
OOAD (37)
Productivity (11)
Programming (168)
Programming Quotables (9)
Rails (31)
Ruby (67)
Save Your Job (58)
scriptaGulous (4)
Software Development Process (23)
TDD (41)
TDDing xorblog (6)
Tools (5)
Web Development (8)
Windows (1)
With (1)
YAGNI (10)

Resources
Agile Manifesto & Principles
Principles Of OOD
ColdFusion
CFUnit
Ruby
Ruby on Rails
JUnit



RSS 2.0: Full Post | Short Blurb
Subscribe by email:

Delivered by FeedBurner