Skip to content

Instantly share code, notes, and snippets.

@skopp
Forked from shurizzle/gist:1223923
Last active December 16, 2015 21:10
Show Gist options
  • Save skopp/5498100 to your computer and use it in GitHub Desktop.
Save skopp/5498100 to your computer and use it in GitHub Desktop.
Turn a github.com URL into a git.io URL.
#gistflow - testing tag/label
#!/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)
@skopp
Copy link
Author

skopp commented May 1, 2013

NOTE: what about /^(https?:\/\/)?(gist\.)?github.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment