Created
November 17, 2010 16:59
-
-
Save tisba/703646 to your computer and use it in GitHub Desktop.
TextMate command snippet for the gemedit gem
This file contains hidden or 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 | |
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The method should be named gem_exists?, shouldn't it? ;-)