diff --git a/flameshot_example.sh b/flameshot_example.sh deleted file mode 100644 index e40981e..0000000 --- a/flameshot_example.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/bin/bash -IMAGEPATH="$HOME/Pictures/" # Where to store screenshots before they're deleted -IMAGENAME="ass" # Not really important, tells Flameshot what file to send and delete -KEY="" # Your ass upload token -DOMAIN="" # Your upload domain (without http:// or https://) - -flameshot config -f "$IMAGENAME" # Make sure that Flameshot names the file correctly -flameshot gui -r -p "$IMAGEPATH" > /dev/null # Prompt the screenshot GUI, also append the random gibberish to /dev/null - -FILE="$IMAGEPATH$IMAGENAME.png" # File path and file name combined - -# Check if file exists to handle Curl and rm errors -# then upload the image and copy the response URL -if [ -f "$FILE" ]; then - echo "$FILE exists." - URL=$(curl -X POST \ - -H "Content-Type: multipart/form-data" \ - -H "Accept: application/json" \ - -H "User-Agent: ShareX/13.4.0" \ - -H "Authorization: $KEY" \ - -F "file=@$IMAGEPATH$IMAGENAME.png" "https://$DOMAIN/" | grep -Po '(?<="resource":")[^"]+') - # printf instead of echo as echo appends a newline - printf "%s" "$URL" | xclip -sel clip - rm "$IMAGEPATH$IMAGENAME.png" # Delete the image locally -else - echo "Aborted." -fi diff --git a/screenshot_example.sh b/screenshot_example.sh new file mode 100644 index 0000000..3799103 --- /dev/null +++ b/screenshot_example.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +# File Options +IMAGEPATH="$HOME/Pictures/" # Where to store screenshots before they are deleted +IMAGENAME="ass" # Not really important, tells this script which image to send and delete +FILE="$IMAGEPATH$IMAGENAME" # for future convenience, please do not edit + + +# Authentication +# If left empty, a local screenshot will be taken and copied to your clipboard. +KEY="" # Your ass upload token +DOMAIN="" # Your upload domain (without http:// or https://) + +# helper function to take flameshot screenshots +takeFlameshot () { + flameshot config -f "${IMAGENAME}" + flameshot gui -r -p "${IMAGEPATH}" > /dev/null +} + +# helper function to take screenshots on wayland using grim + slurp for region capture +takeGrimshot () { + grim -g "$(slurp)" "${FILE}.png" > /dev/null +} + +# decide on the screenshot tool(s) based on display backend +if [[ "${XDG_SESSION_TYPE}" == x11 ]]; then + echo -en "Display backend detected as Xorg (x11), using Flameshot\n" # append new line so that Flameshot messages start at a new line + takeFlameshot # call for the flameshot function +elif [[ "${XDG_SESSION_TYPE}" == wayland ]]; then + echo -en "Display backend detected as Wayland, using grim & slurp" + takeGrimshot # call for the grim function +else + echo -en "Unknown display backend.\n Assuming Xorg and using Flameshot." + takeFlameshot > ./Flameshot.log # will be full of gibberish, but we try it anyway + echo -en "Done. Make sure you check for any errors and report them.\nLogfile located in $(pwd)" +fi + +# check if the screenshot file actually exists before proceeding with uploading/copying to clipboard +if [[ -f "${FILE}.png" ]]; then + # check if KEY and DOMAIN are correct, + # if they are, upload the file to the ass instance + # if not, copy the image to clipboard and exit + if [[ ( -z ${KEY+x} && -v ${DOMAIN+x} ) ]]; then + URL=$(curl -X POST \ + -H "Content-Type: multipart/form-data" \ + -H "Accept: application/json" \ + -H "User-Agent: ShareX/13.4.0" \ + -H "Authorization: $KEY" \ + -F "file=@$FILE" "https://$DOMAIN/" | grep -Po '(?<="resource":")[^"]+') + if [[ "${XDG_SESSION_TYPE}" == x11 ]]; then + # printf instead of echo as echo appends a newline + printf "%s" "$URL" | xclip -sel clip # it is safe to use xclip on xorg, so we don't need wl-copy + elif [[ "${XDG_SESSION_TYPE}" == wayland ]]; then + # if desktop session is wayland instead of xclip, use wl-copy + printf "%s" "$URL" | wl-copy + else + echo -en "Invalid desktop session!\n Exiting." + exit 1 + fi + rm "${FILE}" # Delete the image locally + exit 1 + else + # If domain & key are not set, assume it is a local screenshot and copy the image directly to clipboard + if [[ "${XDG_SESSION_TYPE}" == x11 ]]; then # if display backend is x11, use xclip + # TODO: find a way to copy image to clipboard on qt environments, like KDE Plasma + echo -en "Local screenshots are only available on Wayland (for now).\nExiting..." + exit 1 + elif [[ "${XDG_SESSION_TYPE}" == wayland ]]; then # if display backend is wayland, use wl-clipboard (available on AUR or can be self-compiled) + wl-copy < "${FILE}" + exit 1 + else + echo -en "Local screenshots are only available on Wayland (for now).\nExiting..." + #TODO: find a way to copy image to clipboard on qt environments, like KDE Plasma + exit 1 + fi + fi +else + # Abort screenshot if $FILE.png does not exist + echo "Screenshot aborted." +fi