.dotfiles/.bin/screenshot

50 lines
1.1 KiB
Plaintext
Raw Normal View History

2021-03-30 20:59:59 +00:00
#!/usr/bin/env sh
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"
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
{
xclip -t image/png "$1" -selection clipboard
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
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"
2021-04-23 17:38:05 +00:00
}
2021-03-30 20:59:59 +00:00
2021-07-09 22:50:17 +00:00
main_no_upload()
{
if [ "$(flameshot gui -r | tee $path | wc -c)" -gt 0 ]
2021-04-23 17:38:05 +00:00
then
2021-07-09 22:50:17 +00:00
clip_image $path
2021-04-23 17:38:05 +00:00
fi
2021-07-09 22:50:17 +00:00
}
main()
{
if [ -n "$1" ] && [ -e "$1" ]
then
convert "$1" "$path"
clip_image "$path"
upload_image "$path"
2021-07-09 22:50:17 +00:00
else
if [ "$(flameshot gui -r | tee $path | wc -c)" -gt 0 ]
2021-07-09 22:50:17 +00:00
then
clip_image "$path"
upload_image "$path"
2021-07-09 22:50:17 +00:00
fi
fi
}
case $1 in
no_upload) main_no_upload ;;
*) main "$1" ;;
2021-07-09 22:50:17 +00:00
esac