Skip to content

Instantly share code, notes, and snippets.

@tisba
Created November 17, 2010 16:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tisba/703646 to your computer and use it in GitHub Desktop.
Save tisba/703646 to your computer and use it in GitHub Desktop.
TextMate command snippet for the gemedit gem
#!/usr/bin/env ruby
# REQUIREMENTS:
#
# gem install gemedit
#
# INSTALLATION:
#
# Create a new TextMate command, paste this code, assign an activation shortcut,
# set output to "Show as Tool Tip" and done.
#
# USAGE:
#
# Now you can hit your shortcut
# (CMD+CTRL+E for me) enter a gem name and open it in TextMate. If your cursor
# is inside a word, the script will try to find a gem corresponding to that word.
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
@flippingbits
Copy link

The method should be named gem_exists?, shouldn't it? ;-)

@tisba
Copy link
Author

tisba commented Nov 18, 2010

upsi :) fixed :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment