From: Einar Jørgen Haraldseid <einar@haraldseid.net>
Date: Sat, 27 May 2017 08:12:55 +0000 (+0200)
Subject: Fixed bug, cleanup, added paste function
X-Git-Url: https://git.slaskete.net/einar-bin/commitdiff_plain/62175bff02c30430bae5ce9690d987cd2dc2277c?ds=sidebyside;hp=85e66018144ee26e09e833ce155bfc47a25b0ad4

Fixed bug, cleanup, added paste function
---

diff --git a/screenshot.sh b/screenshot.sh
index 973b581..56ccf5b 100755
--- a/screenshot.sh
+++ b/screenshot.sh
@@ -1,30 +1,36 @@
 #!/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="$(tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 6 | head -n 1).png"
-  gnome-screenshot -f "${LOCALPATH}/${FILENAME}" -p "$@"
-  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}"
+  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 > "${LocalPath}/${FileName}" 2>/dev/null
+  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() {
@@ -38,11 +44,15 @@ case ${1} in
     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
     ;;