Skip to content

Instantly share code, notes, and snippets.

@zunda
Forked from wuputah/cap
Last active August 29, 2015 14:13
Show Gist options
  • Save zunda/55a992e541d351e19dcb to your computer and use it in GitHub Desktop.
Save zunda/55a992e541d351e19dcb to your computer and use it in GitHub Desktop.
#!/bin/sh
scrot -s -e 'cloudapp $f; rm $f'
#!/usr/bin/ruby
# https://gist.github.com/wuputah/cd6a7f3781c288fbbc4c
usage = "#{File.basename($0)} file-to-upload ...\nURLs will be in your clipboard"
# $ gem install --user-install cloudapp_api
require 'cloudapp_api'
config_file = "#{ENV['HOME']}/.cloudapp"
begin
email, password = File.read(config_file).split("\n")
rescue Errno::ENOENT
end
if not password or password.empty?
$stderr.puts "#{config_file} shuold have your email and password (one par line)"
end
if ARGV.empty?
$stderr.puts "usage: #{usage}"
exit 0
end
begin
CloudApp.authenticate(email, password)
urls = ARGV.map do |x|
$stderr.print "Uuploading #{x} as... "
begin
url = CloudApp::Item.create(:upload, {:file => x}).url
url += "/#{File.basename(x)}"
$stderr.puts url
url
rescue SystemCallError => e
$stderr.puts e # and try other files
end
end
# Copy them to your (linux) clipboard.
IO.popen("xclip -i", "w") do |io|
io.print urls.compact.join(",")
end
rescue NameError => e
if "uninitialized constant CloudApp::ResponseError::MultiJson" == e.message
$stderr.puts "Error from CloudApp API"
exit 1
else
raise e
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment