Created
August 4, 2010 14:26
-
-
Save insane-dreamer/508207 to your computer and use it in GitHub Desktop.
send to pastie.org script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# can be called with two optional arguments: | |
# 1. name of file to paste | |
# 2. programming language / parser | |
# | |
# in the absence of 1., the clipboard will be read | |
# in the absence of 2., the default_language (below) will be used | |
# | |
# the returning URL will be copied to the clipboard and opened in browser | |
# | |
# clipboard function works on OSX only | |
require 'net/http' | |
default_language = 'ruby' | |
pastie = 'http://pastie.caboo.se/pastes/create' | |
class Clipboard | |
def self.read | |
IO.popen('pbpaste') {|clipboard| clipboard.read} | |
end | |
def self.write(stuff) | |
IO.popen('pbcopy', 'w+') {|clipboard| clipboard.write(stuff)} | |
end | |
end | |
if ARGV[0] | |
if File.exists?(ARGV[0]) | |
paste = File.open(ARGV[0]).read | |
else | |
# we assume they're passing only the language as a parameter | |
lang = ARGV[0] | |
end | |
end | |
paste ||= Clipboard.read | |
lang ||= ARGV[1] || default_language | |
paste_url = Net::HTTP.post_form(URI.parse(pastie), | |
{"paste_parser" => lang, | |
"paste[authorization]" => "burger", | |
"paste[body]" => paste}).body.match(/href="([^\"]+)"/)[1] | |
Clipboard.write(paste_url) | |
Kernel.system("open #{paste_url}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put together this script because the scripts on pastie.org are outdated. (Can be easily modified to use pastebin.com instead of pastie.org.)