Skip to content

Instantly share code, notes, and snippets.

Created July 22, 2008 14:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save anonymous/1002 to your computer and use it in GitHub Desktop.
Save anonymous/1002 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "tempfile"
GIST_URL = 'http://gist.github.com/gists'
if ARGV.include? "-p"
text = `pbpaste`
elsif !ARGV.empty?
@filename = ARGV.shift
text = File.read(File.expand_path(@filename))
elsif ENV["FILE"]
@filename = ENV["FILE"]
text = File.read(File.expand_path(ENV["FILE"]))
else
test = STDIN.read
end
@filename ||= "Unnamed File"
@extension = File.extname(@filename)
@extension = "txt" if @extension == ""
text_file = Tempfile.open('w+')
text_file << text
text_file.flush
cmd = <<-EOS
curl #{GIST_URL} \
-s -L -o /dev/null -w "%{url_effective}" \
-F "file_ext[gistfile1]=#{@extionson}" \
-F "file_name[gistfile1]=#{@filename}" \
-F "file_contents[gistfile1]=<#{text_file.path}" \
-F "x=27" \
-F "y=27"
EOS
url = %x{#{cmd}}
text_file.close(true)
`echo #{url} | pbcopy`
puts "Copied to pasteboard: #{url}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment