feat: migrate `check_tool`

Co-authored-by: NotAShelf <raf@notashelf.dev>
pull/249/head
Sylvie 6 months ago
parent 9205f18b28
commit f4f5997a0b
No known key found for this signature in database
GPG Key ID: 75AB0FE5B983A3AF

@ -13,6 +13,11 @@
# ! Upload mode (ass=0,cheek=1)
MODE=0
# Function to check if a tool is installed
check_tool() {
command -v "$1" >/dev/null 2>&1
}
# Mode string switcher
get_mode() {
if [[ $MODE -eq 0 ]];
@ -29,14 +34,25 @@ FILE="$IMGPATH/$(get_mode)-$(date +%s).png"
TOKEN=$(cat $IMGPATH/.token)
DOMAIN=$(cat $IMGPATH/.domain)
# Build dynamic Flameshot user-agent
USERAGENT=$(flameshot -v | sed -n -E 's/(Flameshot) (v[0-9]+\.[0-9]+\.[0-9]+) .+/\1-\2/p')
takeScreenshot() {
REQUIRED_TOOLS=("flameshot" "curl" "xclip" "notify-send")
# Check if the proper tools are installed
for tool in "${REQUIRED_TOOLS[@]}"; do
if ! check_tool "$tool"; then
echo "Error: $tool is missing!"
exit 1
fi
done
# Build dynamic Flameshot user-agent
USERAGENT=$(flameshot -v | sed -n -E 's/(Flameshot) (v[0-9]+\.[0-9]+\.[0-9]+) .+/\1-\2/p')
# Take screenshot with Flameshot
flameshot gui -r -p "$FILE" > /dev/null # Append the random gibberish to /dev/null
# Take screenshot with Flameshot
flameshot gui -r -p "$FILE" > /dev/null # Append the random gibberish to /dev/null
# Upload file
if [ -f "$FILE" ]; then
# Upload file
if [ -f "$FILE" ]; then
echo "Uploading $FILE to $(get_mode)..."
# Configure upload fields
@ -61,10 +77,13 @@ if [ -f "$FILE" ]; then
# Copy the URL to clipboard (using printf instead of echo to avoid a newline)
printf "%s" "$URL" | xclip -sel clip
echo "URL copied: $URL"
notify-send -a $(get_mode) -t 2000 "URL copied to clipboard" "<a href=\"$URL\">View in browser</a>"
notify-send -a $(get_mode) -t 4000 "URL copied to clipboard" "<a href=\"$URL\">View in browser</a>"
# Delete local file
rm "$FILE"
else
else
echo "Aborted."
fi
fi
}
takeScreenshot

Loading…
Cancel
Save