Created
September 15, 2009 15:53
-
-
Save dcparker/187404 to your computer and use it in GitHub Desktop.
mategem command. Opens any rubygem or ruby library file in TextMate.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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