Skip to content

Instantly share code, notes, and snippets.

@bakotaco
Forked from defunkt/gitio
Created February 16, 2012 12:04
Show Gist options
  • Save bakotaco/1844374 to your computer and use it in GitHub Desktop.
Save bakotaco/1844374 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.
url = ARGV[0]
code = ARGV[1]
if url !~ /^(https?:\/\/)?(gist\.)?github.com/
abort "* github.com URLs only"
end
if url !~ /^http/
url = "https://#{url}"
end
if code
code = "-F code=#{code}"
end
output = `curl -i http://git.io -F 'url=#{url}' #{code} 2> /dev/null`
if output =~ /Location: (.+)\n?/
puts $1
`echo #$1 | pbcopy 2>/dev/null`
else
puts output
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment