Improve screenshot tool for wayland
This commit is contained in:
parent
018c576357
commit
fdefb7037b
1 changed files with 46 additions and 13 deletions
|
@ -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
|
||||||
printf '%s' "$screenshot_host/$file" | xclip -selection clipboard
|
if [ -n "$WAYLAND_DISPLAY" ]
|
||||||
printf '%s' "$screenshot_host/$file" | xclip -selection primary
|
then
|
||||||
rclone copyto "$1" "$rclone_remote/$file"
|
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"
|
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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue