[TxMt] Wrap selection as link with title

Brett Terpstra brett at circlesixdesign.com
Sun Oct 22 16:12:45 UTC 2006


I'll try curl.  I already tried a whole slew of net:http header  
checks and they all gave me that same error.  The weird thing is that  
if I paste the script into an edit window and hit CTRL-R, it runs  
fine...  just won't run as a command.

Thanks,
Brett

On Oct 22, 2006, at 11:07 AM, Reprisal wrote:

> Probably use net::http to grab the page, and use the response codes  
> to fail gracefully.  Otherwise test for a valid response using curl  
> before calling open?
>
> On Oct 22, 2006, at 11:00 AM, Brett Terpstra wrote:
>
>> Hi everybody.
>>
>> As some of you may have figured out, I work a lot in HTML and CSS  
>> and I have a fetish for descriptive titles on links.  I've been  
>> rewriting the wrap selection as link command and have it all  
>> worked out to grab the title of the link in the clipboard if it  
>> starts with http(s).  I can't get it to validate the link, though.
>>
>> Here's the text of the command:
>>
>> #!/usr/bin/env ruby
>> require "#{ENV['TM_SUPPORT_PATH']}/lib/progress.rb"
>> require 'open-uri'
>> link = "http://site.com"
>> title = #{ENV['TM_SELECTED_TEXT']}
>> s = IO.popen('pbpaste', 'r+').read
>> if s.match(/(http(s?):\/\/)/) then
>> TextMate.call_with_progress(:title => "Opening Link", :message =>  
>> "Retrieving Title for #{s}") do
>>           begin
>>              fp = open(s)
>>          title = fp.read.match(/<title>([^<>]*)<\/title>/i).to_a 
>> [1].strip
>>          link = s
>>            rescue
>>              title = "site unreachable"
>>            end
>> end
>> end
>> print %{<a href="${1:#{link}}" title="${2:#{title}}" > 
>> $TM_SELECTED_TEXT</a>}
>>
>> I've tried all kinds of overly complex methods that all yield the  
>> same results when the link is bogus:
>>
>> /usr/lib/ruby/1.8/timeout.rb:42:in /bin/bash: -c: line 1:  
>> unexpected EOF while looking for matching `''
>> /bin/bash: -c: line 3: syntax error: unexpected end of fileconnect'
>> from /usr/lib/ruby/1.8/net/protocol.rb:64:in /bin/bash: -c: line  
>> 1: unexpected EOF while looking for matching `''
>> /bin/bash: -c: line 3: syntax error: unexpected end of fileopen'
>> from /usr/lib/ruby/1.8/net/http.rb:430:in /bin/bash: -c: line 1:  
>> unexpected EOF while looking for matching `''
>> /bin/bash: -c: line 3: syntax error: unexpected end of filestart'
>> from /usr/lib/ruby/1.8/net/http.rb:324:in /bin/bash: -c: line 1:  
>> unexpected EOF while looking for matching `''
>> /bin/bash: -c: line 3: syntax error: unexpected end of  
>> fileproxy_open'
>> from /usr/lib/ruby/1.8/open-uri.rb:525:in /bin/bash: -c: line 1:  
>> unexpected EOF while looking for matching `''
>> /bin/bash: -c: line 5: syntax error: unexpected end of filepopen'
>> from /Users/brett/Library/Application Support/TextMate/Support/lib/ 
>> progress.rb:11:in
>> This is what I get (and should get, I think) when I run it from a  
>> Ruby dialog:
>> <a href="${1:http://site.com}" title="${2:site unreachable}" > 
>> $TM_SELECTED_TEXT</a>
>>
>> It works great when the site in the clipboard is valid.  Any  
>> suggestions would be appreciated.
>>
>> Thanks,
>> Brett
>>
>>
>> Brett Terpstra : Art Director
>> Circle Six Design, Inc.
>> 111 Riverfront Dr, Suite 204
>>
>>
>>
>>
>> _____________________________________________________________________ 
>> _
>> For new threads USE THIS: textmate at lists.macromates.com
>> (threading gets destroyed and the universe will collapse if you  
>> don't)
>> http://lists.macromates.com/mailman/listinfo/textmate
>
>
> ______________________________________________________________________
> For new threads USE THIS: textmate at lists.macromates.com
> (threading gets destroyed and the universe will collapse if you don't)
> http://lists.macromates.com/mailman/listinfo/textmate




More information about the textmate mailing list