Skip to content

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

62 lines (56 sloc) 1.832 kb
<?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 -wKU
require ENV['TM_SUPPORT_PATH'] + '/lib/escape.rb'
require 'erb'
require 'open-uri'
require 'net/http'
def entity_escape(text)
text.gsub(/&amp;(?!([a-zA-Z0-9]+|#[0-9]+|#x[0-9a-fA-F]+);)/, '&amp;amp;')
end
def make_link(text)
case text
when %r{\A(mailto:)?(.*?@.*\..*)\z}:
"mailto:#{$2.gsub(/./) {sprintf("&amp;#x%02X;", $&amp;.unpack("U")[0])}}"
when %r{http://www.(amazon.(?:com|co.uk|co.jp|ca|fr|de))/.+?/([A-Z0-9]{10})/[-a-zA-Z0-9_./%?=&amp;]+}:
"http://#{$1}/dp/#{$2}"
when %r{\A[a-zA-Z][a-zA-Z0-9.+-]*://.*\z}:
entity_escape(text)
when %r{\A(www\..*|.*\.(com|uk|net|org|info))\z}:
"http://#{entity_escape text}"
when %r{\A.*\.(com|uk|net|org|info)\z}:
"http://#{entity_escape text}"
when %r{\A\S+\z}:
entity_escape(text)
else
"http://example.com/"
end
end
url = make_link %x{__CF_USER_TEXT_ENCODING=$UID:0x8000100:0x8000100 pbpaste}.strip
if url =~ /^http:\/\// and url != 'http://example.com/'
eval 'title = fp.read.match(/&lt;title&gt;([^&lt;&gt;]*)&lt;\/title&gt;/i).to_a[1].strip rescue nil' if fp = open(url) rescue nil
end
input = STDIN.read
print ERB.new(ENV['TM_LINK_FORMAT']).result
</string>
<key>fallbackInput</key>
<string>word</string>
<key>input</key>
<string>selection</string>
<key>keyEquivalent</key>
<string>^L</string>
<key>name</key>
<string>Wrap Word / Selection as Link</string>
<key>output</key>
<string>insertAsSnippet</string>
<key>scope</key>
<string>text</string>
<key>uuid</key>
<string>A42DC78E-6588-476F-8A00-40B8CCC6D2E0</string>
</dict>
</plist>
Jump to Line
Something went wrong with that request. Please try again.