-
-
Save yoshinari-nomura/4fd46ae3707469537bd5dc364e24f12b to your computer and use it in GitHub Desktop.
This file contains 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/ruby | |
# -*- coding: utf-8 -*- | |
# Please add INDEX to speedup the SQL queries which use LIKE clauses: | |
# | |
# sqlite3 "#{DICT_FILE}" 'CREATE INDEX dict_key ON dict (key COLLATE NOCASE);' | |
SQLITE = "sqlite3" | |
DICT_FILE = "'#{ENV['HOME']}/foo/bar/mouseoverdictionary.sqlite'" | |
word = ARGV.shift | |
## XXX: sanitizing is required for WORD. | |
sql = "SELECT * FROM dict WHERE key COLLATE NOCASE LIKE '#{word}%' LIMIT 100;" | |
IO.popen "#{SQLITE} #{DICT_FILE} \"#{sql}\"" do |f| | |
while line = f.gets | |
line.sub!('|', "\n") | |
line.gsub!(' \ ', "\n") | |
print line | |
print "\n" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment