Created
July 19, 2011 21:13
-
-
Save bkenny/1093726 to your computer and use it in GitHub Desktop.
Shorten
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
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