img/img.sh

13 lines
521 B
Bash
Raw Normal View History

2014-02-13 15:13:19 -08:00
#!/bin/bash
2014-02-13 15:29:56 -08:00
# https://github.com/Ceryn/img
# Call with '-s' to target only a selection of the screen.
2014-02-13 15:29:56 -08:00
2014-02-13 15:13:19 -08:00
clientid='3e7a4deb7ac67da'
2014-10-23 12:45:25 -07:00
img=$(mktemp '/tmp/img-XXXXXX.png')
2014-02-13 15:13:19 -08:00
scrot -z "$@" $img >/dev/null 2>&1 || exit
2014-02-13 15:13:19 -08:00
res=$(curl -sH "Authorization: Client-ID $clientid" -F "image=@$img" "https://api.imgur.com/3/upload")
echo $res | grep -qo '"status":200' && link=$(echo $res | sed -e 's/.*"link":"\([^"]*\).*/\1/' -e 's/\\//g')
2014-10-23 12:52:48 -07:00
test -n "$link" && (printf $link | xclip; printf "\a" && rm "$img") || echo "$res" > "$img.error"