Skip to content

Instantly share code, notes, and snippets.

@gnufied
Forked from johnl/screenshot.sh
Created June 11, 2013 11:19
Show Gist options
  • Save gnufied/5756126 to your computer and use it in GitHub Desktop.
Save gnufied/5756126 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Copyright 2013 John Leach <[email protected]>
#
# Distributed under terms of the MIT license
#
# Takes a screeshot using scrot and uploads it via scp and sticks the
# url on the clipboard as quickly as possible.
#
# For speed, it cheats and puts the url on the clipboard *before*
# uploading.
#
# Requires the scrot screenshot tool, scp, sha256sum, xclip and
# notify-send. Rquires ruby too, but a bit unecessarily.
#
set -e
URLBASE="http://example.com/screenshots"
SCPURL="[email protected]:www/screenshots"
if [ -d /dev/shm ] ; then
TMPDIR="/dev/shm"
else
TMPDIR=$TMP
fi
# FIXME: unsafe, use mktemp instead
TMPFILE="$TMPDIR/scrot-${USER}-`date +"%s"`.png"
sleep 0.1 # needed due to a bug in gnome-shell with keyboard focus
scrot -s $TMPFILE
CSUM=`sha256sum $TMPFILE | ruby -e 'puts STDIN.read.to_i(16).to_s(36)'`
FILENAME=`date +%Y%m%d`-${CSUM}.png
URL=$URLBASE/${FILENAME}
echo -e "`date`:\t$TMPFILE\t$URL" >> $HOME/screenshot.log
echo $URL | xclip
scp $TMPFILE $SCPURL/${FILENAME} &&
/usr/bin/notify-send -t 2000 -u low "Screenshot uploaded successfully" &&
rm $TMPFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment