mirror of https://github.com/tycrek/ass
parent
afc943c2bb
commit
e201da1e55
@ -1,81 +1,95 @@
|
|||||||
#!/bin/bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# File Options
|
# Script Configuration
|
||||||
IMAGEPATH="$HOME/Pictures/" # Where to store screenshots before they are deleted
|
IMAGEPATH="$HOME/Pictures"
|
||||||
IMAGENAME="ass" # Not really important, tells this script which image to send and delete
|
IMAGENAME="ass"
|
||||||
FILE="$IMAGEPATH$IMAGENAME" # for future convenience, please do not edit
|
FILE="${IMAGEPATH}/${IMAGENAME}.png"
|
||||||
|
LOG_DIR=$(pwd)
|
||||||
|
CONFIG_FILE="config.sh"
|
||||||
# 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://)
|
|
||||||
|
|
||||||
|
# Load configuration if available
|
||||||
|
# this is useful if you want to source keys from a secret file
|
||||||
|
if [ -f "$CONFIG_FILE" ]; then
|
||||||
|
source "${CONFIG_FILE}"
|
||||||
|
fi
|
||||||
|
|
||||||
# helper function to take flameshot screenshots
|
# Function to take Flameshot screenshots
|
||||||
takeFlameshot() {
|
takeFlameshot() {
|
||||||
flameshot config -f "${IMAGENAME}"
|
flameshot config -f "${IMAGENAME}"
|
||||||
flameshot gui -r -p "${IMAGEPATH}" >/dev/null
|
flameshot gui -r -p "${IMAGEPATH}" >/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
# helper function to take screenshots on wayland using grim + slurp for region capture
|
# Function to take Wayland screenshots using grim + slurp
|
||||||
takeGrimshot() {
|
takeGrimshot() {
|
||||||
grim -g "$(slurp)" "${FILE}.png" > /dev/null
|
grim -g "$(slurp)" "${FILE}" >/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
# decide on the screenshot tool(s) based on display backend
|
# Function to remove the taken screenshot
|
||||||
if [[ "${XDG_SESSION_TYPE}" == x11 ]]; then
|
removeTargetFile() {
|
||||||
echo -en "Display backend detected as Xorg (x11), using Flameshot\n" # append new line so that Flameshot messages start at a new line
|
echo -en "Process complete.\nRemoving image.\n"
|
||||||
takeFlameshot # call for the flameshot function
|
rm -v "${FILE}"
|
||||||
elif [[ "${XDG_SESSION_TYPE}" == wayland ]]; then
|
}
|
||||||
echo -en "Display backend detected as Wayland, using grim & slurp\n"
|
|
||||||
takeGrimshot # call for the grim function
|
|
||||||
else
|
|
||||||
echo -en "Unknown display backend.\n Assuming Xorg and using Flameshot.\n"
|
|
||||||
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)\n"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# check if the screenshot file actually exists before proceeding with uploading/copying to clipboard
|
# Function to upload target image to your ass instance
|
||||||
if [[ -f "${FILE}.png" ]]; then
|
uploadScreenshot() {
|
||||||
# check if KEY and DOMAIN are correct,
|
echo -en "KEY & DOMAIN are set. Attempting to upload to your ass instance.\n"
|
||||||
# if they are, upload the file to the ass instance
|
|
||||||
# if not, copy the image to clipboard and exit
|
|
||||||
if [[ ( -n "${KEY}" && -n "${DOMAIN}" ) ]]; then
|
|
||||||
echo -en "KEY & DOMAIN are set\nAttempting to upload to your ass instance.\n"
|
|
||||||
URL=$(curl -X POST \
|
URL=$(curl -X POST \
|
||||||
-H "Content-Type: multipart/form-data" \
|
-H "Content-Type: multipart/form-data" \
|
||||||
-H "Accept: application/json" \
|
-H "Accept: application/json" \
|
||||||
-H "User-Agent: ShareX/13.4.0" \
|
-H "User-Agent: ShareX/13.4.0" \
|
||||||
-H "Authorization: $KEY" \
|
-H "Authorization: $KEY" \
|
||||||
-F "file=@${FILE}.png" "https://$DOMAIN/" | grep -Po '(?<="resource":")[^"]+')
|
-F "file=@${FILE}" "https://$DOMAIN/" | grep -Po '(?<="resource":")[^"]+')
|
||||||
if [[ "${XDG_SESSION_TYPE}" == x11 ]]; then
|
if [[ "${XDG_SESSION_TYPE}" == x11 ]]; then
|
||||||
# printf instead of echo as echo appends a newline
|
printf "%s" "$URL" | xclip -sel clip
|
||||||
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
|
elif [[ "${XDG_SESSION_TYPE}" == wayland ]]; then
|
||||||
# if desktop session is wayland instead of xclip, use wl-copy (wl-clipboard)
|
|
||||||
printf "%s" "$URL" | wl-copy
|
printf "%s" "$URL" | wl-copy
|
||||||
else
|
else
|
||||||
echo -en "Invalid desktop session!\nExiting.\n"
|
echo -en "Invalid desktop session!\nExiting.\n"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
echo -en "Process complete.\nRemoving image.\n"
|
}
|
||||||
rm "${FILE}.png" # Delete the image locally
|
|
||||||
else
|
localScreenshot() {
|
||||||
echo -en "KEY & DOMAIN are not set\nAttempting local screenshot.\n"
|
echo -en "KEY & DOMAIN variables are not set. Attempting local screenshot.\n"
|
||||||
# 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 [[ "${XDG_SESSION_TYPE}" == x11 ]]; then # if display backend is x11, use xclip
|
xclip -sel clip -target image/png <"${FILE}"
|
||||||
xclip -sel clip -target image/png < "${FILE}.png"
|
elif [[ "${XDG_SESSION_TYPE}" == wayland ]]; then
|
||||||
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}"
|
wl-copy <"${FILE}"
|
||||||
else
|
else
|
||||||
echo -en "Unknown display backend...\nAssuming Xorg and using xclip...\n"
|
echo -en "Unknown display backend. Assuming Xorg and using xclip.\n"
|
||||||
xclip -sel clip -target image/png < "${FILE}.png"
|
xclip -sel clip -target image/png <"${FILE}"
|
||||||
fi
|
fi
|
||||||
echo -en "Process complete.\nRemoving image.\n"
|
}
|
||||||
rm "${FILE}.png"
|
|
||||||
|
# Check if the screenshot tool based on display backend
|
||||||
|
if [[ "${XDG_SESSION_TYPE}" == x11 ]]; then
|
||||||
|
echo -en "Display backend detected as Xorg (x11), using Flameshot\n"
|
||||||
|
takeFlameshot
|
||||||
|
elif [[ "${XDG_SESSION_TYPE}" == wayland ]]; then
|
||||||
|
echo -en "Display backend detected as Wayland, using grim & slurp\n"
|
||||||
|
takeGrimshot
|
||||||
|
else
|
||||||
|
echo -en "Unknown display backend. Assuming Xorg and using Flameshot\n"
|
||||||
|
takeFlameshot >"${LOG_DIR}/flameshot.log"
|
||||||
|
echo -en "Done. Make sure you check for any errors and report them.\nLogfile located in '${LOG_DIR}'\n"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Check if the screenshot file exists before proceeding
|
||||||
|
if [[ -f "${FILE}" ]]; then
|
||||||
|
if [[ -n "$KEY" && -n "$DOMAIN" ]]; then
|
||||||
|
# Upload the file to the ass instance
|
||||||
|
uploadImage
|
||||||
|
|
||||||
|
# Remove image
|
||||||
|
removeTargetFile
|
||||||
else
|
else
|
||||||
# Abort screenshot if $FILE.png does not exist
|
# Take a screenshot locally
|
||||||
echo -en "Target file was not found.\nAbording screenshot.\n"
|
localScreenshot
|
||||||
|
|
||||||
|
# Remove image
|
||||||
|
removeTargetFile
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo -en "Target file ${FILE} was not found. Aborting screenshot.\n"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in new issue