Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: e810aecb68
Fetching contributors…

Cannot retrieve contributors at this time

file 47 lines (45 sloc) 1.628 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>#!/usr/bin/env ruby
require "#{ENV['TM_SUPPORT_PATH']}/lib/progress.rb"
require "#{ENV['TM_SUPPORT_PATH']}/lib/exit_codes.rb"
require 'open-uri'
require 'erb'


def getWikiDef(input)
  TextMate.call_with_progress(:title =&gt; "Contacting Wikipedia", :message =&gt; "Looking for definition of #{input}") do
   response = open("http://en.wikipedia.org/wiki/Special:Search?search=#{input}",
   "User-Agent" =&gt; "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1",
   "Referer" =&gt; "http://www.ruby-lang.org/") {|f| $response = f }
   url = response.base_uri
   # borrowed from iamrice.org
   fp = open(url)
   title = "Wikipedia Entry: " + fp.read.match(/&lt;title&gt;([^&lt;&gt;]*)&lt;\/title&gt;/i).to_a[1]
   if title.include? "Search"
   TextMate.exit_show_tool_tip "No definition found"
   else
   return title.sub(/ - Wikipedia, the free encyclopedia/, ''), url
   end
  end
end
input = STDIN.read
title, url = getWikiDef(input)
print ERB.new(ENV['TM_LINK_FORMAT']).result</string>
<key>fallbackInput</key>
<string>word</string>
<key>input</key>
<string>selection</string>
<key>name</key>
<string>Basic Wikipedia</string>
<key>output</key>
<string>insertAsSnippet</string>
<key>scope</key>
<string>text</string>
<key>uuid</key>
<string>71C47F5F-41FA-40E8-A13A-238BC30984D1</string>
</dict>
</plist>
Something went wrong with that request. Please try again.