From d0bbb6693449c279e887529d751edc6dcf94640a Mon Sep 17 00:00:00 2001
From: Tobias Reisinger <tobias@msrg.cc>
Date: Fri, 25 Nov 2022 12:36:10 +0100
Subject: [PATCH] Improve screenshot tool (replace s3cmd with rclone) and fix
 other stuff

---
 .bin/screenshot | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/.bin/screenshot b/.bin/screenshot
index cfd8d44..bc270b1 100755
--- a/.bin/screenshot
+++ b/.bin/screenshot
@@ -1,25 +1,27 @@
 #!/usr/bin/env sh
 
-s3_bucket=public.serguzim.me/screenshots
-s3_host=https://sos-de-fra-1.exo.io
-path=/tmp/screenshot.png
-file=$(date "+%F_%H-%M-%S").png
+rclone_remote="s3-serguzim-me:public/screenshots"
+screenshot_host="https://s3.serguzim.me/public/screenshots"
+path="/tmp/screenshot.png"
+file="$(date '+%F_%H-%M-%S').png"
 
 clip_image()
 {
-    xclip -t image/png $1 -selection clipboard
+    xclip -t image/png "$1" -selection clipboard
 }
 
 upload_image()
 {
-    echo -n "$s3_host/$s3_bucket/$file" | xclip -selection primary
-    s3cmd put -P $1 s3://$s3_bucket/$file
+	# to have link available in clipboard manager
+    printf '%s' "$screenshot_host/$file" | xclip -selection clipboard
+    printf '%s' "$screenshot_host/$file" | xclip -selection primary
+    rclone copyto "$1" "$rclone_remote/$file"
     notify-send -a "Screenshot" "Uploaded screenshot to s3"
 }
 
 main_no_upload()
 {
-    if flameshot gui -r > $path
+    if [ "$(flameshot gui -r | tee $path | wc -c)" -gt 0 ]
     then
         clip_image $path
     fi
@@ -29,19 +31,19 @@ main()
 {
     if [ -n "$1" ] && [ -e "$1" ]
     then
-        convert $1 $path
-        clip_image $path
-        upload_image $path
+        convert "$1" "$path"
+        clip_image "$path"
+        upload_image "$path"
     else
-        if flameshot gui -r > $path
+        if [ "$(flameshot gui -r | tee $path | wc -c)" -gt 0 ]
         then
-            clip_image $path
-            upload_image $path
+            clip_image "$path"
+            upload_image "$path"
         fi
     fi
 }
 
 case $1 in
     no_upload)   main_no_upload ;;
-    *)           main $1 ;;
+    *)           main "$1" ;;
 esac