#!/usr/bin/env ruby
SUPPORT = ENV['TM_SUPPORT_PATH']
DIALOG = SUPPORT + '/bin/CocoaDialog.exe'
selected_word = ENV['TM_CURRENT_WORD']
x = "--xpos #{ENV['TM_CARET_XPOS']} "
y = "--ypos #{ENV['TM_CARET_YPOS']} "
if selected_word != nil
menu = []
all_words = STDIN.read.split(/\b/)
all_words.each do |word|
if word != selected_word
if word.index(selected_word) == 0
menu << word + " "
end
end
end
menu.uniq!
if menu.length < 1
abort
elsif menu.length == 1
print menu[0].sub(selected_word, '').strip
else
selected = %x`"#{DIALOG}" menu --items #{menu} #{x} #{y}`.to_i - 1
print menu[selected].sub(selected_word, '').strip
end
end
Read more: http://feeds.dzone.com/~r/dzone/snippets/~3/NBQzoU0m1bw/12585