-
-
Save subtleGradient/2936 to your computer and use it in GitHub Desktop.
gistie.rb Paste code to gist.github.com from the shell!
This file contains hidden or 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 | |
# GIST | |
# Paste to Gist.GitHub.com from the Shell | |
# | |
# Forked by Thomas Aylott / subtleGradient | |
# at 4096a998b6c6a0043e1ce158d43639b5db78a61c | |
# | |
# Original "gistie" by Pieter de Bie <[email protected]> | |
# Based on a "Pastie" task by someone | |
# | |
require "tempfile" | |
class Gist | |
GIST_URL = 'http://gist.github.com/gists' | |
GIST_LOGIN_URL = 'https://gist.github.com/session' | |
def login_cookie | |
begin | |
username = File.read(File.expand_path('~/.gist_username')).chomp | |
password = File.read(File.expand_path('~/.gist_pass')).chomp | |
rescue => e | |
return nil | |
end | |
headers = `curl --insecure #{GIST_LOGIN_URL} -s -i -F "login=#{username}" -F "password=#{password}"` | |
if headers =~ /Set-Cookie: (.*); do/ | |
return $1 | |
end | |
return nil | |
end | |
def initialize(filename, extension, data, login=false) | |
cookie = login_cookie if login | |
text_file = Tempfile.open('w+') | |
text_file << data | |
text_file.flush | |
cmd = "curl #{GIST_URL} \\\n" | |
cmd += "-b '#{cookie}' \\\n" if cookie | |
cmd += <<-EOS | |
-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) | |
end | |
def to_s | |
@url | |
end | |
end | |
if __FILE__ == $0 | |
login = !ARGV.delete('-a') | |
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 == "" | |
puts Gist.new(@filename, @extension, data, login) | |
end |
This file contains hidden or 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
ln -s "${PWD}/gist" ~/bin/gist | |
chmod +x ~/bin/gist | |
touch ~/.gist_username | |
chmod 600 ~/.gist_username | |
touch ~/.gist_pass | |
chmod 600 ~/.gist_pass | |
echo "Put your login and password for GitHub into '~/.gist_username' and '~/.gist_pass'" | |
$EDITOR ~/.gist_username | |
$EDITOR ~/.gist_pass |
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>beforeRunningCommand</key> | |
<string>nop</string> | |
<key>bundleUUID</key> | |
<string>2E6B9F06-DDB6-4707-A2BB-8751CF1722A0</string> | |
<key>command</key> | |
<string>cat|gist -a "$TM_FILENAME" | |
</string> | |
<key>input</key> | |
<string>selection</string> | |
<key>keyEquivalent</key> | |
<string>^@V</string> | |
<key>name</key> | |
<string>Paste to Gist.GitHub Anonymously</string> | |
<key>output</key> | |
<string>showAsHTML</string> | |
<key>uuid</key> | |
<string>CF0D0F28-0F67-4348-B68E-6A677EEA7C97</string> | |
</dict> | |
</plist> |
This file contains hidden or 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
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
<plist version="1.0"> | |
<dict> | |
<key>beforeRunningCommand</key> | |
<string>nop</string> | |
<key>bundleUUID</key> | |
<string>2E6B9F06-DDB6-4707-A2BB-8751CF1722A0</string> | |
<key>command</key> | |
<string>cat|gist "$TM_FILENAME" | |
</string> | |
<key>input</key> | |
<string>selection</string> | |
<key>keyEquivalent</key> | |
<string>^@V</string> | |
<key>name</key> | |
<string>Paste to Gist.GitHub</string> | |
<key>output</key> | |
<string>showAsHTML</string> | |
<key>uuid</key> | |
<string>6BD4B983-AF2F-4380-AEB1-EE0B431D977E</string> | |
</dict> | |
</plist> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment