hi all, I found the "Hyperlink helper bundle" a very useful tool for creating wikipedia and other links.
For some time now, however, running "Lookup Word / Selection on Wikipedia and link" has lead to this error:
env: ruby\rrequire: No such file or directory
Has this function been rolled into another bundle or support dropped?
thanks for your help, tim
FYI, the code is
#!/usr/bin/env ruby require "#{ENV['TM_SUPPORT_PATH']}/lib/progress.rb" require "#{ENV['TM_SUPPORT_PATH']}/lib/exit_codes.rb" require "#{ENV['TM_SUPPORT_PATH']}/lib/ui.rb" require "#{ENV['TM_SUPPORT_PATH']}/lib/escape" require 'cgi' require 'open-uri' require 'erb'
def cap_all_words(string) return string.split(" ").map{|w| w.capitalize}.join(" ") end
def follow_redirect(page) pagename = page.match(/var\swgPageName\s=\s"(.*?) ";/).to_a[1].gsub(/\'/,'%27') url = %{http://en.wikipedia.org/wiki/#%7Bpagename%7D%7D content = open(url).read return url, content, pagename end #follow_redirect
def select_link(links) linklist = links.map { |p| p[0] } item = TextMate::UI.request_item :title => "Multiple Definitions", :prompt => "Please select a definition", :items => linklist TextMate.exit_discard if item.nil? return links[linklist.index(item)] end # select_link
def check_for_search(page) TextMate.exit_show_tool_tip "No definition found" if page.match(/ <title>([^<>]*)</title>/i).to_a[1].include? "Search" return page end # check_for_search
def check_for_multiple_results(page,phrase,pagename) if page.match(/(</b>\scan\sbe:</p>)|(</b>\smay\srefer\sto:</p>)/ i) then open("http://en.wikipedia.org/wiki/Special:Export/#%7Bpagename%7D") {| body| links = [] body.read.scan(/[[([^|]]*)[|]?[^]]*]]/) { |link| links.push(link) } choice = select_link(links) TextMate.exit_discard if choice.nil? TextMate.exit_replace_text(%{<a href="http://en.wikipedia.org/wiki/# {CGI.escape(choice[0]).gsub('+','_')}" title="Wikipedia Entry: #{choice[0]}">#{phrase}</a>}) } end end #check_for_multiple_results
def check_for_disambiguation(page,phrase,pagename) # if page.match(/#{phrase}[\s]?(disambiguation)/i) then if page.include? "(disambiguation)" # findlink = page.match(/"(/wiki/#{pagename}_%28disambiguation %29)"/i) # open("http://en.wikipedia.org#%7Bfindlink%5B1%5D%7D") {|body| open("http://en.wikipedia.org/wiki/Special:Export/#%7Bpagename%7D_ %28disambiguation%29") {|body| content = body.read links = [] content.scan(/[[([^|]]*)[|]?[^]]*]]/) { |link| links.push(link) } choice = select_link(links) TextMate.exit_discard if choice.nil? TextMate.exit_replace_text(%{<a href="http://en.wikipedia.org/wiki/# {CGI.escape(choice[0]).gsub('+','_')}" title="Wikipedia Entry: #{choice[0]}">#{phrase}</a>}) } end end #check_for_disambiguation
def getWikiDef(phrase) TextMate.call_with_progress(:title => "Contacting Wikipedia", :message => "Looking for definition of #{phrase}") do escapedUrl = "http://en.wikipedia.org/wiki/Special:Search? search=#{CGI.escape(phrase).gsub(/\'/,'%27')}" @response = open( escapedUrl, "User-Agent" => "TextMate 1.5.5") content = @response.read if content.scan(/Redirected\sfrom/) url, content, pagename = follow_redirect(content) # confirmed = TextMate::UI.request_confirmation :button1 => "Accept", :button2 => "Cancel", :title => "Redirected to "#{pagename} "", :prompt => "Accept Redirection?" # TextMate.exit_discard unless confirmed else url = @response.base_uri pagename = phrase end check_for_search(content) check_for_multiple_results(content,phrase,pagename) check_for_disambiguation(content,phrase,pagename) title = "Wikipedia Entry: " + pagename.gsub(/_/, ' ') return url, title, phrase end end
url, title, input = getWikiDef(STDIN.read) print ERB.new(ENV['TM_LINK_FORMAT']).result
On Apr 21, 2008, at 6:47 PM, Timothy Bates wrote:
For some time now, however, running "Lookup Word / Selection on Wikipedia and link" has lead to this error:
env: ruby\rrequire: No such file or directory
Has this function been rolled into another bundle or support dropped?
Is the error message you got exactly correct? Can you double-check it?
Takaaki
On 21 Apr 2008, at 11:47, Timothy Bates wrote:
I found the "Hyperlink helper bundle" a very useful tool for creating wikipedia and other links.
For some time now, however, running "Lookup Word / Selection on Wikipedia and link" has lead to this error:
env: ruby\rrequire: No such file or directory
Has this function been rolled into another bundle or support dropped?
Maybe your shebang is using a carriage return rather than a line feed as line terminator (the former being \r the latter being \n -- interesting though that env converts the character to it’s printable escape code when showing the error)?
Try revert the bundle to the default version (by removing it from ~/ Library/Application Support/TextMate/Bundles).
On 21 Apr 2008, at 4:41 PM, Allan Odgaard wrote:
On 21 Apr 2008, at 11:47, Timothy Bates wrote:
I found the "Hyperlink helper bundle" a very useful tool for creating wikipedia and other links. For some time now, however, running "Lookup Word / Selection on Wikipedia and link" has lead to this error: env: ruby\rrequire: No such file or directory Has this function been rolled into another bundle or support dropped?
Maybe your shebang is using a carriage return rather than a line feed as line terminator (the former being \r the latter being \n -- interesting though that env converts the character to it’s printable escape code when showing the error)?
Try revert the bundle to the default version (by removing it from ~/ Library/Application Support/TextMate/Bundles).
Dear Allan: tried that - same error persisted. S
Next I copied the source of the command into a TM file and did find \r --> \n
Nothing was found, but pasting that source back in to the bundle fixed the error. go figure
Thanks for your help!
tim