Improve screenshot tool (replace s3cmd with rclone) and fix other stuff

This commit is contained in:
Tobias Reisinger 2022-11-25 12:36:10 +01:00
parent f0af2d26b0
commit d0bbb66934
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE

View file

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