Created
September 11, 2011 08:11
-
-
Save defunkt/1209316 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. | |
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 |
@basicallydan @dwijnand - Yep seems code
no longer works. A bug was reported in my library (https://github.com/tanepiper/node-gitio) and I can't get it to work with new urls (test pass because it's older urls that were set)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@basicallydan Are you sure you can still use the
code
option? Can you provide a complete example? Because I'm finding that I can't..