.dotfiles/.bin/screenshot

83 lines
1.5 KiB
Plaintext
Raw Normal View History

2021-03-30 20:59:59 +00:00
#!/usr/bin/env sh
2023-07-01 20:35:40 +00:00
tool="grim"
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"
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()
{
# 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"
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)
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
}
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