diff --git "a/Commands/Paste Selection : Line Online\342\200\246.tmCommand" "b/Commands/Paste Selection : Line Online\342\200\246.tmCommand" index b51be59..19b3761 100644 --- "a/Commands/Paste Selection : Line Online\342\200\246.tmCommand" +++ "b/Commands/Paste Selection : Line Online\342\200\246.tmCommand" @@ -162,7 +162,11 @@ URL_REGEXP = %r{ }xi def connect_to_server(name, url, *args) - $status, res = :unknown, nil + $status, res, response = :unknown, nil, '???' + + tmpFile = Tempfile.new('tm_paste_headers') + tmpFilePath = tmpFile.path.dup + tmpFile.close! server = $1 if url =~ %r{.*?://(.*?)(/.*)?$} TextMate.call_with_progress(:title => "Paste to #{name}", :message => "Contacting Host “#{server}”…", :cancel => lambda { $status = :cancel; Process.kill("INT", -Process.pid) }) do @@ -174,7 +178,7 @@ def connect_to_server(name, url, *args) pid = fork do STDOUT.reopen(wr) rd.close - exec('curl', url, '-sLo/dev/null', '-w%{url_effective}', *args) + exec('curl', url, "-D#{tmpFilePath}", '-sLo/dev/null', '-w%{url_effective}', *args) end Process.setpgid(0, oldpgid) wr.close @@ -187,8 +191,11 @@ def connect_to_server(name, url, *args) thr.join end + response = $1 if File.read(tmpFilePath) =~ /\AHTTP\/[0-9.]+ (.*?)\r?\n/ + File.unlink(tmpFilePath) + $status = :error if res !~ URL_REGEXP || res == url # pastie returns the initial URL on some errors - return $status, res + return $status, res, response end def paste_stdin(priv, wrap) @@ -209,7 +216,7 @@ def paste_stdin(priv, wrap) ext = find_language_ext start_time = Time.now - $status, res = connect_to_server("Pastie", PASTE_URL, + $status, res, response = connect_to_server("Pastie", PASTE_URL, "-HExpect:", "-Fpaste[parser]=plaintext", "-Fpaste[restricted]=#{priv}", @@ -223,11 +230,11 @@ def paste_stdin(priv, wrap) open(File.expand_path('~/Library/Logs/Pastie.log'), 'a') do |io| amount = (File.size(text_file.path) + File.size(html_file.path)).to_s.gsub(/\d{1,3}(?=(\d{3})+(?!\d))/, '\0,') + " bytes" time_elapsed = '%.1f seconds' % (Time.now - start_time) - io << start_time.strftime('%F %T %Z: ') << + io << start_time.strftime('%F %T %Z: ') << response << " " << case $status when :timeout then "Timeout pasting #{amount} after #{time_elapsed}\n" when :cancel then "User cancelled pasting of #{amount} after #{time_elapsed}\n" - when :error then "Unknown error after #{time_elapsed} pasting #{amount}\n" + when :error then "Error after #{time_elapsed} pasting #{amount}\n" else "Pasted #{amount} in #{time_elapsed}: #{res}\n" end end @@ -235,13 +242,13 @@ def paste_stdin(priv, wrap) paste_via_rafb = case $status when :timeout then TextMate::UI.alert(:warning, "Timeout Pasting", "There was a problem pasting your text (timeout).\nWould you like to use RAFB.net instead?", "Paste via RAFB", "Cancel") != "Cancel" - when :error then TextMate::UI.alert(:warning, "Error Pasting", "There was a problem pasting your text (unknown).\nWould you like to use RAFB.net instead?", "Paste via RAFB", "Cancel") != "Cancel" + when :error then TextMate::UI.alert(:warning, "Error Pasting", "There was a problem pasting your text, pastie.org responded with #{response}\nWould you like to use RAFB.net instead?", "Paste via RAFB", "Cancel") != "Cancel" else false end if paste_via_rafb mode = $& if ENV['TM_MODE'] =~ /^(C89|C|C\+\+|C#|Java|Pascal|Perl|PHP|PL\/I|Python|Ruby|SQL|VB)$/ - $status, res = connect_to_server("RAFB.net", "http://rafb.net/paste/paste.php", + $status, res, response = connect_to_server("RAFB.net", "http://rafb.net/paste/paste.php", "-Fnick=#{ENV['USER']}", "-Fcvt_tabs=#{ENV['TM_TAB_SIZE']}", "-Ftext=<#{text_file.path}",