Something went wrong. Try again.
dotfiles
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273#!/usr/bin/env ruby# This script can use some improving...require 'optparse'require 'open3'TIME = Time.nowDATE_PATH = TIME.strftime '%Y/%m/%d'LOCAL = '/tmp'FILENAME = "#{TIME.strftime '%Y-%m-%d_%H-%M-%S'}.png"REMOTE = 'scrotify' # In ~/.ssh/configTARGET = "/var/www/files.sharparam.com/public_html/#{DATE_PATH}"URL = "http://files.sharparam.com/#{DATE_PATH}/#{FILENAME}"options = { mode: :all}# Apparently the keyring variables cannot be accessed from scripts that run# from i3's exec tool, so we have to manually set the socket here.sock = `gpgconf --list-dirs agent-ssh-socket`.stripENV['SSH_AUTH_SOCK'] = sockOptionParser.new do |opts| opts.banner = "Usage: #{$0} [options]" opts.on('-s', '--select', 'Screenshot region') do options[:mode] = :select end opts.on('-a', '--active', 'Screenshot active window') do options[:mode] = :active endend.parse!def error(msg) `notify-send -u critical "Scrotify" "#{msg}"` abort msgenddef maim(args = '') `maim -u #{args} #{LOCAL}/#{FILENAME}` error 'maim failed' unless $?.exitstatus == 0 `notify-send -u low "Scrotify" "Uploading screenshot..."` `ssh -q #{REMOTE} mkdir -p #{TARGET}/` error 'ssh mkdir failed' unless $?.exitstatus == 0 `rsync -q #{LOCAL}/#{FILENAME} #{REMOTE}:#{TARGET}/` error 'rsync failed' unless $?.exitstatus == 0 `rm #{LOCAL}/#{FILENAME}` Open3.popen2('xclip -sel c') { |i, _, _| i.print(URL); i.close; } `notify-send -u normal "Scrotify" "#{URL}"`enddef capture(mode = :all) case mode when :select region = `slop -f %g`.strip maim "-g #{region}" when :active `xdotool getactivewindow getwindowgeometry` =~ /(\d+),(\d+).+?(\d+)x(\d+)/m maim "-g #{$3}x#{$4}+#{$1}+#{$2}" else maim endendcapture options[:mode]