Skip to content

Instantly share code, notes, and snippets.

@samchouse
Last active August 23, 2021 17:29
Show Gist options
  • Select an option

  • Save samchouse/a1ddc9667ce6013548577f66f887cffc to your computer and use it in GitHub Desktop.

Select an option

Save samchouse/a1ddc9667ce6013548577f66f887cffc to your computer and use it in GitHub Desktop.
Screenshot something with FlameShot and upload it to an image host
#!/bin/zsh
keys=("upload.systems key")
urls=("https://api.upload.systems/images/upload")
rnd_idx=$(($RANDOM % 1 + 1))
key=${keys[rnd_idx]}
url=${urls[rnd_idx]}
temp_file="/tmp/screenshot.png"
flameshot gui -r > $temp_file
if [[ $(file --mime-type -b $temp_file) != "image/png" ]]; then
rm $temp_file
notify-send "Screenshot aborted" -a "Flameshot" && exit 1
fi
if [ $rnd_idx -eq 1 ]; then
command=$(curl $url -H "Content-Type: multipart/form-data" -H "User-Agent: curl-upload" -F "file=@"$temp_file -F "key=$key" 2>/dev/null)
image_url=$(echo -n $command | jq -r ".url")
echo -n $image_url | xclip -sel c
notify-send "Image URL copied to clipboard" "$image_url" -a "Flameshot - upload.systems" -i $temp_file -t 10000
rm $temp_file
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment