remux.sh for remuxing obs recordings to mp4 and preserve audio tracks
[einar-bin] / screenshot.sh
index 762005f4d3acdb95e8cf7f3cd598db2ed13a9886..d9205477e96a7612ad3b190b0f7443cbe15a26ca 100755 (executable)
@@ -1,30 +1,48 @@
 #!/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.
 #!/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
 # 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}/Pictures/Screenshots/"
+UrlBase="https://eina.rjh.im/g"
 
 function errcho() {
   >&2 echo -e "$@"
 }
 
 function take_screenshot() {
 
 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}"
-  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}"
+  FileID="$(tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 6 | head -n 1)"
+  FileName="${FileID}.png"
+  if [ "$*" = "clipboard" ] || [ "$*" = "jpg" ]; then
+    xclip -out -selection clipboard -t image/png > "/tmp/${FileName}" 2>/dev/null
+    if [ "$(file -b --mime-type "/tmp/${FileName}")" == "image/png" ]; then
+      if [ "$*" = "jpg" ]; then
+        convert "/tmp/${FileName}" "/tmp/${FileID}.jpg"
+        rm "/tmp/${FileName}"
+        FileName="${FileID}.jpg"
+      fi
+      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() {
 }
 
 function show_error() {
@@ -38,11 +56,18 @@ case ${1} in
     take_screenshot -w -b -e shadow
     ;;
   -a|--area|-s|--selection)
     take_screenshot -w -b -e shadow
     ;;
   -a|--area|-s|--selection)
+    sleep 0.2
     take_screenshot -a
     ;;
   ""|-f|--full)
     take_screenshot
     ;;
     take_screenshot -a
     ;;
   ""|-f|--full)
     take_screenshot
     ;;
+  -c|--clipboard|-p|--paste)
+    take_screenshot clipboard
+    ;;
+  -j|--jpg)
+    take_screenshot jpg
+    ;;
   *)
     show_error
     ;;
   *)
     show_error
     ;;