Skip to content

Instantly share code, notes, and snippets.

@bretthoerner
Last active August 29, 2015 14:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bretthoerner/d975a3b592358a7092b3 to your computer and use it in GitHub Desktop.
Save bretthoerner/d975a3b592358a7092b3 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -euo pipefail
if [ $# -eq 0 ]; then
sleep 0.2 # xmonad holds keyboard; race condition fix
scrot -s -e "$0 \$f"
exit
fi
FILE=$1
# from creating an imgur application
CLIENT_ID="X"
CLIENT_SECRET="X"
# anonymous upload, won't go to user dir
# curl --header "Authorization: Client-ID ${CLIENT_ID}" --form "image=@${FILE}" "https://api.imgur.com/3/image" 2> /dev/null | jq .data.link
# refresh token from authorizing, used: https://github.com/jacobgreenleaf/imgur-python
REFRESH_TOKEN="X"
# these expire every hour, so just grab one every time we want to POST
ACCESS_TOKEN=$(curl -s \
--data "refresh_token=${REFRESH_TOKEN}&client_id=${CLIENT_ID}&client_secret=${CLIENT_SECRET}&grant_type=refresh_token" \
"https://api.imgur.com/oauth2/token" \
| jq .access_token \
| sed -e 's/"//g')
# as user
URL=$(curl -s \
--header "Authorization: Bearer ${ACCESS_TOKEN}" \
--form "image=@${FILE}" \
"https://api.imgur.com/3/image" \
| jq .data.link \
| sed -e 's/"//g')
echo "${URL}" | xclip -selection clipboard
notify-send "Uploaded: ${URL}"
rm -f "${FILE}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment