Skip to content

Instantly share code, notes, and snippets.

@icebeat
Created April 8, 2011 17:02
Show Gist options
  • Save icebeat/910281 to your computer and use it in GitHub Desktop.
Save icebeat/910281 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Save: Nothing
# Input: Select text or Word
# Output: Show as Tool tip
# Key Equivalent: Your choice
# Scope Selector: Nothing
require ENV["TM_SUPPORT_PATH"] + "/lib/ui.rb"
require ENV["TM_SUPPORT_PATH"] + "/lib/textmate.rb"
space = ENV['TM_SCOPE'].match(/text.html.basic/) ? "" : " "
current_word = (ENV['TM_CURRENT_WORD'].nil? || ENV['TM_CURRENT_WORD'].match(/\.|\"/)) ? "" : "#{ENV['TM_CURRENT_WORD']}"
files = `grep "\\.#{current_word}" -in -d recurse --include=*.css #{ENV['TM_PROJECT_DIRECTORY']}`
abort "Sorry, nothing found" if files.empty?
file = ''
items = []
files.each do |file|
class_name = "#{file.split(':')[2]}".match(/\.#{current_word}([^\.%\),\{\s:]+)/i)
class_found = class_name.nil? ? "" : current_word + class_name[1].lstrip
items << class_found + space if class_found.length > 2
end
items = items.uniq.sort do |a,b| a.upcase <=> b.upcase end
TextMate::UI.complete(items)
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment