Skip to content

Instantly share code, notes, and snippets.

@shurizzle
Created September 17, 2011 13:14
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save shurizzle/1223923 to your computer and use it in GitHub Desktop.
Save shurizzle/1223923 to your computer and use it in GitHub Desktop.
Turn a github.com URL into a git.io URL.
#!/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