Skip to content

Instantly share code, notes, and snippets.

@janv
Forked from tisba/gist:703646
Created November 17, 2010 19:41
Show Gist options
  • Save janv/703924 to your computer and use it in GitHub Desktop.
Save janv/703924 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "#{ENV['TM_SUPPORT_PATH']}/lib/exit_codes.rb"
require "#{ENV['TM_SUPPORT_PATH']}/lib/ui.rb"
require "rubygems"
require 'active_support/inflector'
current_word = ENV['TM_CURRENT_WORD'] || ""
def gem_exists?(name)
search_cmd = "#{(ENV['TM_GEM'] || "gem")} search #{name} | grep -e \"^#{name}\""
puts search_cmd
system(search_cmd)
name if $? == 0
end
if current_word != ""
gem_name = gem_exists?(current_word)
gem_name = gem_exists?(current_word.strip.downcase) unless gem_name
gem_name = gem_exists?(current_word.strip.underscore) unless gem_name
end
unless gem_name
TextMate::UI.request_string(
:title => 'Open Rubygem',
:prompt => 'Name of the gem to open',
:default => current_word,
:button1 => 'Open'
)
TextMate.exit_discard if gem_name.nil?
gem_name = gem_name.strip.downcase
end
# Let TM_GEM point to your RVM gem command
system("#{(ENV['TM_GEM'] || "gem")} edit -e mate #{gem_name}")
puts "Gem not found" unless $? == 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment