2021-03-30 20:59:59 +00:00
|
|
|
#!/usr/bin/env sh
|
|
|
|
|
2023-07-01 20:35:40 +00:00
|
|
|
tool="grim"
|
|
|
|
|
2022-11-25 11:36:10 +00:00
|
|
|
rclone_remote="s3-serguzim-me:public/screenshots"
|
|
|
|
screenshot_host="https://s3.serguzim.me/public/screenshots"
|
2023-07-01 20:35:40 +00:00
|
|
|
screenshot_path="/tmp/screenshot.webp"
|
2023-02-02 22:26:51 +00:00
|
|
|
file="$(date '+%F_%H-%M-%S').webp"
|
2021-03-30 20:59:59 +00:00
|
|
|
|
2021-07-09 22:50:17 +00:00
|
|
|
clip_image()
|
2021-04-23 17:38:05 +00:00
|
|
|
{
|
2023-07-01 20:35:40 +00:00
|
|
|
if [ -n "$WAYLAND_DISPLAY" ]
|
|
|
|
then
|
2023-07-06 21:38:19 +00:00
|
|
|
wl-copy -t image/png < "$screenshot_path"
|
2023-07-01 20:35:40 +00:00
|
|
|
else
|
|
|
|
xclip -t image/png "$screenshot_path" -selection clipboard
|
|
|
|
fi
|
2021-07-09 22:50:17 +00:00
|
|
|
}
|
2021-03-30 20:59:59 +00:00
|
|
|
|
2021-07-09 22:50:17 +00:00
|
|
|
upload_image()
|
|
|
|
{
|
2022-11-25 11:36:10 +00:00
|
|
|
# to have link available in clipboard manager
|
2023-07-01 20:35:40 +00:00
|
|
|
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 primary
|
|
|
|
fi
|
|
|
|
|
|
|
|
rclone copyto "$screenshot_path" "$rclone_remote/$file"
|
2021-04-01 17:00:33 +00:00
|
|
|
notify-send -a "Screenshot" "Uploaded screenshot to s3"
|
2021-04-23 17:38:05 +00:00
|
|
|
}
|
2021-03-30 20:59:59 +00:00
|
|
|
|
2023-07-01 20:35:40 +00:00
|
|
|
call_screenshot_tool() {
|
|
|
|
case $tool in
|
|
|
|
flameshot)
|
|
|
|
result=$(flameshot gui -r | tee $screenshot_path | wc -c) ;;
|
|
|
|
grim)
|
2024-05-20 16:59:26 +00:00
|
|
|
result=$(grim -g "$(slurp -c bd93f9)" - | tee $screenshot_path | wc -c) ;;
|
2023-07-01 20:35:40 +00:00
|
|
|
*)
|
|
|
|
echo "Unknown screenshot tool: $tool"
|
|
|
|
return 1 ;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
if [ "$result" -gt 0 ]
|
|
|
|
then
|
|
|
|
return 0
|
|
|
|
else
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2021-07-09 22:50:17 +00:00
|
|
|
main_no_upload()
|
|
|
|
{
|
2023-07-01 20:35:40 +00:00
|
|
|
if call_screenshot_tool
|
2021-04-23 17:38:05 +00:00
|
|
|
then
|
2023-07-06 21:38:19 +00:00
|
|
|
clip_image
|
2021-04-23 17:38:05 +00:00
|
|
|
fi
|
2021-07-09 22:50:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
main()
|
|
|
|
{
|
|
|
|
if [ -n "$1" ] && [ -e "$1" ]
|
|
|
|
then
|
2023-07-01 20:35:40 +00:00
|
|
|
convert "$1" "$screenshot_path"
|
|
|
|
upload_image
|
|
|
|
clip_image
|
2021-07-09 22:50:17 +00:00
|
|
|
else
|
2023-07-01 20:35:40 +00:00
|
|
|
if call_screenshot_tool
|
2021-07-09 22:50:17 +00:00
|
|
|
then
|
2023-07-01 20:35:40 +00:00
|
|
|
upload_image
|
|
|
|
clip_image
|
2021-07-09 22:50:17 +00:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
case $1 in
|
2024-01-09 15:53:25 +00:00
|
|
|
"--no-upload") main_no_upload ;;
|
|
|
|
*) main "$1" ;;
|
2021-07-09 22:50:17 +00:00
|
|
|
esac
|