better error handling for rm and curl (#104)

Co-authored-by: Josh Moore <josh.moore@jmoore.dev>
pull/114/head
NotAShelf 3 years ago committed by GitHub
parent fc82a6d6b3
commit 161c3f865e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,16 +5,23 @@ KEY="" # Your ass upload token
DOMAIN="" # Your upload domain (without http:// or https://) DOMAIN="" # Your upload domain (without http:// or https://)
flameshot config -f "$IMAGENAME" # Make sure that Flameshot names the file correctly flameshot config -f "$IMAGENAME" # Make sure that Flameshot names the file correctly
flameshot gui -r -p "$IMAGEPATH" # Prompt the screenshot GUI flameshot gui -r -p "$IMAGEPATH" > /dev/null # Prompt the screenshot GUI, also append the random gibberish to /dev/null
# Upload the image and copy the response URL FILE="$IMAGEPATH$IMAGENAME.png" # File path and file name combined
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 # 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

Loading…
Cancel
Save