Created
August 18, 2010 12:17
-
-
Save kaiwren/534507 to your computer and use it in GitHub Desktop.
Open a gem in TextMate (supports opening specific versions)
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 -wKU | |
gemname = ARGV[0] | |
version = ARGV[1] | |
exit unless gemname | |
possible = `gem list #{gemname} | tail`.strip | |
versions = possible.gsub(/.*\(/, '').gsub(/\)$/, '').split(', ') | |
if versions.empty? | |
puts "#{gemname} not found" | |
exit | |
end | |
realname = possible.gsub(/\(.*\)$/, '').strip | |
selected_version = versions.include?(version) ? version : versions.first | |
specifically = "#{realname}-#{selected_version}" | |
current_path = `gem which #{realname}`.strip | |
path = File.expand_path(File.join(current_path, '..', '..', '..', specifically)) | |
puts "Launching mate at #{path}" | |
`mate #{path}` if File.exist?(path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment