Created
October 15, 2015 23:09
-
-
Save colby/fc57b45ed47650167852 to your computer and use it in GitHub Desktop.
UPLOADS TO IMGUR, GOT IT?
This file contains hidden or 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
#!/usr/bin/env bash | |
# variables | |
img="$1" | |
tmp=/tmp/imgur | |
id='3e7a4deb7ac67da' | |
link='https://api.imgur.com/3/upload' | |
# functions | |
errcho() { | |
>&2 echo "$*" | |
exit 1 | |
} | |
check() { | |
which "$1" || errcho "imgur: missing dependency: $1" | |
} | |
# deps | |
grep=$(check grep) | |
curl=$(check curl) | |
tr=$(check tr) | |
# args | |
[ $# -lt 1 ] && errcho "imgur: requires an image file path." | |
# main | |
$curl -sH "Authorization: Client-ID $id" -F "image=@${img}" "$link" > "$tmp" || errcho "imgur: curl failed." | |
if [[ $(cat "$tmp") =~ http ]]; then | |
$grep -oE "http:.*\.[a-z]{3,4}" "$tmp" | $tr -d '\\' | |
else | |
errcho "imgur: $(cut -d'"' -f6 "$tmp" | $tr '[:upper:]' '[:lower:]')" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment