Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@perusio
Forked from defunkt/gitio
Created May 10, 2013 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perusio/5553913 to your computer and use it in GitHub Desktop.
Save perusio/5553913 to your computer and use it in GitHub Desktop.
#!/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`
else
puts output
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment