Merge branch 'master' of ssh://git.slaskete.net/srv/git/einar-bin
authorEinar Jørgen Haraldseid <einar@haraldseid.net>
Tue, 7 Apr 2015 21:25:13 +0000 (23:25 +0200)
committerEinar Jørgen Haraldseid <einar@haraldseid.net>
Tue, 7 Apr 2015 21:25:13 +0000 (23:25 +0200)
screenshot.sh [new file with mode: 0755]

diff --git a/screenshot.sh b/screenshot.sh
new file mode 100755 (executable)
index 0000000..858797a
--- /dev/null
@@ -0,0 +1,50 @@
+#!/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 
+# 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"
+
+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}"
+}
+
+function show_error() {
+  errcho "Please use one of: -w, --window, -a, --area, -s, --selection,"
+  errcho "                   -f, --full or no argument at all."
+  exit 1
+}
+
+case ${1} in
+  -w|--window)
+    take_screenshot -w -b -e shadow
+    ;;
+  -a|--area|-s|--selection)
+    take_screenshot -a
+    ;;
+  ""|-f|--full)
+    take_screenshot
+    ;;
+  *)
+    show_error
+    ;;
+esac
+