Last active
August 29, 2015 14:04
-
-
Save bretthoerner/d975a3b592358a7092b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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