Created
February 13, 2012 18:50
-
-
Save ahoward/1819027 to your computer and use it in GitHub Desktop.
~/bin/gemdir
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 | |
# usage: gemdir gemname | |
# | |
# eg: cd `gemdir yajl` | |
# | |
require 'rubygems' | |
arg = ARGV.first | |
unless arg | |
puts File.join(Gem.dir, "gems") | |
exit | |
end | |
which = arg.dup | |
which << '*' if which | |
entries = | |
Dir[ File.join(Gem.dir, "gems", "#{ which }") ].select{|entry| test ?d, entry}.sort | |
case entries.size | |
when 0 | |
abort "no gem #{ which }" | |
when 1 | |
puts entries.first | |
else | |
all_same_name = entries.map{|e| File.basename(e).split('-').first}.uniq.size == 1 | |
if all_same_name | |
puts entries.last | |
else | |
unless STDIN.tty? | |
warn "ambiguous gemname #{ arg.inspect }" | |
end | |
abort(entries.join("\n")) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment