Improve screenshot tool for wayland

This commit is contained in:
Tobias Reisinger 2023-07-01 22:35:40 +02:00
parent 018c576357
commit fdefb7037b
Signed by: serguzim
GPG key ID: 13AD60C237A28DFE

View file

@ -1,29 +1,62 @@
#!/usr/bin/env sh #!/usr/bin/env sh
tool="grim"
rclone_remote="s3-serguzim-me:public/screenshots" rclone_remote="s3-serguzim-me:public/screenshots"
screenshot_host="https://s3.serguzim.me/public/screenshots" screenshot_host="https://s3.serguzim.me/public/screenshots"
path="/tmp/screenshot.webp" screenshot_path="/tmp/screenshot.webp"
file="$(date '+%F_%H-%M-%S').webp" file="$(date '+%F_%H-%M-%S').webp"
clip_image() clip_image()
{ {
xclip -t image/png "$1" -selection clipboard if [ -n "$WAYLAND_DISPLAY" ]
then
wc-copy -t image/png < "$screenshot_path"
else
xclip -t image/png "$screenshot_path" -selection clipboard
fi
} }
upload_image() upload_image()
{ {
# to have link available in clipboard manager # to have link available in clipboard manager
if [ -n "$WAYLAND_DISPLAY" ]
then
wl-copy "$screenshot_host/$file"
wl-copy -p "$screenshot_host/$file"
else
printf '%s' "$screenshot_host/$file" | xclip -selection clipboard printf '%s' "$screenshot_host/$file" | xclip -selection clipboard
printf '%s' "$screenshot_host/$file" | xclip -selection primary printf '%s' "$screenshot_host/$file" | xclip -selection primary
rclone copyto "$1" "$rclone_remote/$file" fi
rclone copyto "$screenshot_path" "$rclone_remote/$file"
notify-send -a "Screenshot" "Uploaded screenshot to s3" notify-send -a "Screenshot" "Uploaded screenshot to s3"
} }
call_screenshot_tool() {
case $tool in
flameshot)
result=$(flameshot gui -r | tee $screenshot_path | wc -c) ;;
grim)
result=$(grim -g "$(slurp)" - | tee $screenshot_path | wc -c) ;;
*)
echo "Unknown screenshot tool: $tool"
return 1 ;;
esac
if [ "$result" -gt 0 ]
then
return 0
else
return 1
fi
}
main_no_upload() main_no_upload()
{ {
if [ "$(flameshot gui -r | tee $path | wc -c)" -gt 0 ] if call_screenshot_tool
then then
clip_image $path clip_image $screenshot_path
fi fi
} }
@ -31,14 +64,14 @@ main()
{ {
if [ -n "$1" ] && [ -e "$1" ] if [ -n "$1" ] && [ -e "$1" ]
then then
convert "$1" "$path" convert "$1" "$screenshot_path"
upload_image "$path" upload_image
clip_image "$path" clip_image
else else
if [ "$(flameshot gui -r | tee $path | wc -c)" -gt 0 ] if call_screenshot_tool
then then
upload_image "$path" upload_image
clip_image "$path" clip_image
fi fi
fi fi
} }