Skip to content

Instantly share code, notes, and snippets.

@bkenny
Created July 19, 2011 21:13
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 bkenny/1093726 to your computer and use it in GitHub Desktop.
Save bkenny/1093726 to your computer and use it in GitHub Desktop.
Shorten
require 'rubygems'
require 'yourls'
# For each URL provided in the argument list
# run through it and shorten it.
ARGV.each do|a|
# Create a new Yourls instance with the shortener URL and API key.
yourls = Yourls.new('http://bkenn.me', your_api_key_here)
# Pass it the argument/url provided from the command line to shorten.
tiny = yourls.shorten("#{a}")
# Copy the new shorten URL.
IO.popen('pbcopy', 'r+') { |clipboard| clipboard.puts tiny.short_url }
puts 'Copied ' + tiny.short_url
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment