Created
September 17, 2011 13:14
-
-
Save shurizzle/1223923 to your computer and use it in GitHub Desktop.
Turn a github.com URL into a git.io URL.
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 | |
# Usage: gitio URL [CODE] | |
# | |
# Turns a github.com URL | |
# into a git.io URL | |
# | |
# Copies the git.io URL to your clipboard. | |
require 'net/http' | |
require 'clipboard' | |
class Git | |
URI = URI.parse('http://git.io/').freeze | |
def self.io (url, code=nil) | |
pars = {'url' => url } | |
pars.merge!({'code' => code.to_s}) if code | |
res = Net::HTTP.post_form(URI, pars) | |
puts(res['location'] ? Clipboard.copy(res['location']) : res.body) | |
end | |
end | |
Git.io(*ARGV) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment