Skip to content

Instantly share code, notes, and snippets.

@dcparker
Created September 15, 2009 15:53
Show Gist options
  • Save dcparker/187404 to your computer and use it in GitHub Desktop.
Save dcparker/187404 to your computer and use it in GitHub Desktop.
mategem command. Opens any rubygem or ruby library file in TextMate.
#!/usr/bin/env ruby
# mategem (bash command)
require 'rubygems'
gemname = ARGV[0]
paths = $:.to_a.dup
begin
gem gemname
new_paths = $:.to_a.dup - paths
where = new_paths.last
rescue Gem::LoadError
begin
where = (
File.exists?('gems/gemrc.yml') ?
`gem which --config-file gems/gemrc.yml #{gemname}` :
`gem which #{gemname}`
).chomp
rescue LoadError
warn "Can't find ruby library file or shared library #{gemname}"
exit
end
end
if match = where.match(/(.*\/gems\/[^\/]+)/)
gemroot = match[1]
exec "mate #{gemroot}"
else
if File.exists?(where)
exec "mate #{where}"
else
puts "Couldn't understand location: #{where}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment