I don’t know if its because I’m nosy, or because I’m a control freak, or perhaps both, but I really do like to read the source code. It occurs to me that this is probably why I feel so at home in the open source world.

As much as I like something like Cocoa, it pains me not to be able to trace problems all the way down the stack. Even java solved this problem by shipping with its own source.

Proclivities aside, I really like source, and am always looking for ways to make it easier to get at. cd /usr/lib/ruby/gems/1.8/gems gets old quick.

I started with this little cough gem from Dr Nic. Integrating it with my shell, I could now type

1
$ gems activerecord

and up pops the activerecord gem in Textmate. So some new releases of activerecord came out, and suddenly my naive script is giving me the old version. Without looking too far into it I added gem requirement support so that I could type

1
$ gems activerecord '>=2'

and get a recent activerecord in Textmate. As good as this is, I was really after something with less typing and smarter pants. Well tonight I cracked it and I thought I’d open the source:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#!/usr/bin/env ruby

require ENV['TM_SUPPORT_PATH']+"/lib/ui"
require 'rubygems'

gems = Gem.source_index.latest_specs.collect {|spec| spec.full_name}.sort

TextMate::UI.request_item(:title => 'open a gem', :items => gems) do |selected_gem|
	gem_path = Gem.source_index.specification(selected_gem).full_gem_path
	%x{open -a TextMate #{gem_path}}
end

Honestly, that’s it! Bung that in a command using Textmate’s Bundle Editor and assign it a key (I gave it cmd-shift-G, as I don’t regularly search backwards).

Double click on one and you’re golden… neat.

  1. Dr Nic says:

    Nice UI.

    I later integrated that pastie into a gem find_gem.

    Has two command-line apps: find_gem name, and edit_gem name; the later opening up the gem into TextMate etc.

    Also has some nice autocompletions for bash if you look in the readme, I think.

  2. cammo says:

    Wicked! I will be using this alot!

  3. Marc Jeanson says:

    Nice work!

  4. Marc Jeanson says:

    Nice work!

  5. Evan Light says:

    Cool. While tiny, why not make it into a gem as well? Or perhaps hand it off to Giles Bowkett and make it part of the utility_belt gem. Seems appropriate for it.

  6. Evan Light says:

    Ok, forget what I said about utility_belt integration; it's focused on IRB enhancements. This is a command line enhancement.

  7. Daniel De Aguiar says:

    Great post. This is really helpful!

  8. Lee says:

    You might want to check out my little gem called gemedit, which allows gems to be opened in any editor and has command line completion.

    http://gemedit.rubyforge.org/

  9. Dave Newman says:

    Sweeeeeeeeeeeeeeeeet

Post a comment


( lesstile enabled - surround code blocks with ---)