Skip to content

Instantly share code, notes, and snippets.

@defunkt
Created September 11, 2011 08:11

Revisions

  1. defunkt renamed this gist Sep 17, 2011. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. defunkt revised this gist Sep 17, 2011. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gistio
    Original file line number Diff line number Diff line change
    @@ -9,7 +9,7 @@
    url = ARGV[0]
    code = ARGV[1]

    if url !~ /^(https?:\/\/)?github.com/
    if url !~ /^(https?:\/\/)?(gist\.)?github.com/
    abort "* github.com URLs only"
    end

  3. defunkt created this gist Sep 11, 2011.
    30 changes: 30 additions & 0 deletions gistio
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    #!/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?:\/\/)?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