Skip to content

Instantly share code, notes, and snippets.

@badboy
Created January 12, 2013 00:10
Show Gist options
  • Save badboy/4515101 to your computer and use it in GitHub Desktop.
Save badboy/4515101 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'digest/sha1'
require 'tempfile'
require 'fileutils'
URL = 'YOUR_URL'
SSH_HOST = 'YOUR_HOST'
SSH_HOST_DIR = "#{SSH_HOST}:PATH_ON_SERVER"
SCP_COMMAND = [ 'scp' ]
def sha1(fname)
Digest::SHA1.hexdigest(Time.now.to_s+fname)[0,10] + fname[/(\.\w+)/, 1]
end
if ARGV.include?('-h')
puts <<-EOF
Usage: #{File.basename($0)} [options]"
Take a screenshot and upload it to the server.
Options are passed to scrot.
Best use:
-s interactively choose a window or rectangle with the mouse
EOF
exit 1
end
scrnshot = ['scrot'] + ARGV
tmpfile = Tempfile.new(["screenshot", ".png"])
tmpfile.close
file_path = tmpfile.path
filename = File.basename file_path
scrnshot << file_path
puts '> '+scrnshot*' '
if !system(*scrnshot)
puts "screenshot failed!"
exit 1
end
FileUtils.chmod 0644, file_path
`notify-send "scrup" "Screenshot taken. Uploading..."`
onlinename = sha1(filename)
com = SCP_COMMAND << file_path << "#{SSH_HOST_DIR}/#{onlinename}"
puts '> '+com*' '
if system(*com)
url = "#{URL}/#{onlinename}"
puts url
`xdg-open #{url}`
else
puts "upload failed!"
exit 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment