Skip to content

Instantly share code, notes, and snippets.

@insane-dreamer
Created August 4, 2010 14:26
Show Gist options
  • Save insane-dreamer/508207 to your computer and use it in GitHub Desktop.
Save insane-dreamer/508207 to your computer and use it in GitHub Desktop.
send to pastie.org script
#!/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}")
@insane-dreamer
Copy link
Author

Put together this script because the scripts on pastie.org are outdated. (Can be easily modified to use pastebin.com instead of pastie.org.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment