#!/bin/bash
# A quick and dirty script to take a screenshot, upload it via scp
# and put a link to it in the clipboard for easy pasting to i.e. IRC.
-# It assumes a lot of things, e.g. that ssh to the target host has
+# It assumes a lot of things, e.g. that ssh to the target host has
# been set up with a working private key, and that xclip and
# gnome-screenshot is installed.
#
# If all you have is a hammer, everything looks like a nail.
# Settings
-REMOTEUSER="einar"
-REMOTEHOST="wowbagger.slaskete.net"
-REMOTEPATH="/var/www/eina.rjh.im/screenshots/"
-LOCALPATH="${HOME}/ownCloud/Screenshots/"
-URLBASE="https://eina.rjh.im/screenshots"
+RemoteUser="einar"
+RemoteHost="wowbagger.slaskete.net"
+RemotePath="/var/www/eina.rjh.im/screenshots/"
+LocalPath="${HOME}/ownCloud/Screenshots/"
+UrlBase="https://eina.rjh.im/g"
function errcho() {
>&2 echo -e "$@"
}
function take_screenshot() {
- FILENAME="$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 6 | head -n 1).png"
- gnome-screenshot -f "${LOCALPATH}/${FILENAME}" -p "$@"
- scp -q "${LOCALPATH}/${FILENAME}" "${REMOTEUSER}@${REMOTEHOST}:${REMOTEPATH}"
- printf "${URLBASE}/${FILENAME}"|xclip -selection p
- printf "${URLBASE}/${FILENAME}"|xclip -selection c
- notify-send -i applets-screenshooter "screenshot.sh" "Screenshot published to ${URLBASE}/${FILENAME}"
+ FileName="$(tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 6 | head -n 1).png"
+ if [ "$@" = "clipboard" ]; then
+ xclip -out -selection clipboard -t image/png > "/tmp/${FileName}" 2>/dev/null
+ if [ "$(file -b --mime-type /tmp/${FileName})" == "image/png" ]; then
+ mv "/tmp/${FileName}" "${LocalPath}/"
+ else
+ rm "/tmp/${FileName}"
+ notify-send -i applets-screenshooter "screenshot.sh" "Tried to post image from clipboard, but found no image there."
+ fi
+ else
+ gnome-screenshot -f "${LocalPath}/${FileName}" -p "$@"
+ fi
+ if [ -f "${LocalPath}/${FileName}" ]; then
+ scp -q "${LocalPath}/${FileName}" "${RemoteUser}@${RemoteHost}:${RemotePath}"
+ echo -n "${UrlBase}/${FileName}"|xclip -selection p
+ echo -n "${UrlBase}/${FileName}"|xclip -selection c
+ notify-send -i applets-screenshooter "screenshot.sh" "Screenshot published to ${UrlBase}/${FileName}"
+ fi
}
function show_error() {
take_screenshot -w -b -e shadow
;;
-a|--area|-s|--selection)
+ sleep 0.2
take_screenshot -a
;;
""|-f|--full)
take_screenshot
;;
+ -c|--clipboard|-p|--paste)
+ take_screenshot clipboard
+ ;;
*)
show_error
;;