Skip to content

Instantly share code, notes, and snippets.

@kaiwren
Created August 18, 2010 12:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaiwren/534507 to your computer and use it in GitHub Desktop.
Save kaiwren/534507 to your computer and use it in GitHub Desktop.
Open a gem in TextMate (supports opening specific versions)
#!/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