-
-
Save martinisoft/12231 to your computer and use it in GitHub Desktop.
command-line posting to gist
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/env ruby | |
# Made by Pieter de Bie <[email protected]> | |
# Based on a "Pastie" task by someone | |
require "tempfile" | |
GIST_URL = 'http://gist.github.com/gists' | |
GIST_LOGIN_URL = 'https://gist.github.com/session' | |
USERNAME = "martinisoft" | |
TOKEN = "6ef8395fecf207165f1a82178ae1b984" | |
def login_cookie | |
headers = `curl --insecure #{GIST_LOGIN_URL} -s -i -F"login=#{USERNAME}" -F "token=#{PASSWORD}"` | |
if headers =~ /Set-Cookie: (.*); do/ | |
return $1 | |
end | |
return nil | |
end | |
def create_snippet(filename, extension, data, cookie) | |
text_file = Tempfile.open('w+') | |
text_file << data | |
text_file.flush | |
cmd = <<-EOS | |
curl #{GIST_URL} \ | |
-b '#{cookie}' \ | |
-s -L -o /dev/null -w "%{url_effective}" \ | |
-F "file_ext[gistfile1]=#{extension}" \ | |
-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) | |
return url | |
end | |
if ARGV.include? "-p" | |
data = `pbpaste` | |
elsif !ARGV.empty? | |
@filename = ARGV.shift | |
data = File.read(File.expand_path(@filename)) | |
elsif ENV["FILE"] | |
@filename = ENV["FILE"] | |
data = File.read(File.expand_path(ENV["FILE"])) | |
else | |
data = STDIN.read | |
end | |
@filename ||= "Unnamed File" | |
@extension = File.extname(@filename) | |
@extension = "txt" if @extension == "" | |
url = create_snippet(@filename, @extension, data, login_cookie) | |
`echo #{url} | pbcopy` | |
puts "Copied to pasteboard: #{url}" |
Yup, its a little old, but there are some command line clients out there if I recall. Check out https://rubygems.org/gems/gist
im going to create a windows thing that you press a hot key and it snags your clipboard highlight and passes everything through their web interface. so it can work in any editor where you highlight your code and run a script to pass it along.
…-Dave
---
From: Aaron Kalin [email protected]
To: davidrenne [email protected]
Sent: Monday, October 24, 2011 7:29 PM
Subject: Re: gist gist: 12231
Yup, its a little old, but there are some command line clients out there if I recall. Check out https://rubygems.org/gems/gist
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/12231
Does it still work?
@vinitcool76 no idea, I don't think it will because of their recent API changes.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
i was just trying to reverse engineer gist to post data to and i found this. they really need an API or something.... will check this out