Last active
May 7, 2020 16:46
-
-
Save connordavison/ccf73e4714a006ac2a78 to your computer and use it in GitHub Desktop.
gnome-screenshot-imgur
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 | |
# gnome-screenshot-imgur | |
# Upload a screenshot directly to imgur from CLI; see `man gnome-screenshot` for | |
# params (-f is reserved) | |
# | |
# Generate temp file for image | |
tmp=$(mktemp --suffix=.png) | |
# Take screenshot as per user's params | |
gnome-screenshot -f $tmp $@ | |
# API Key provided by Alan@imgur.com | |
apikey="b3625162d3418ac51a9ee805b1840452" | |
# Check curl is available | |
hash curl 2> /dev/null || { | |
echo "Couln't find curl, which is required." >&2 | |
exit 1 | |
} | |
# Base URL for Imgur | |
url="http://imgur.com/api/upload.xml" | |
# Upload the image (might need this in future: -H "Expect: ") | |
res=$(curl -F "key=$apikey" -F "image=@$tmp" $url 2> /dev/null) | |
# Case that curl could not be completed | |
if [ $? -ne 0 ]; then | |
echo "Curl failed!" >&2 | |
exit 2 | |
fi | |
# Case that curl completed, but Imgur could not upload | |
if [ $(echo $res | grep -c "<error_msg>") -gt 0 ]; then | |
echo $res | sed -r 's/.*<error_msg>(.*)<\/error_msg>.*/\1/' >&2 | |
exit 3 | |
fi | |
# Parse the response and output our stuff | |
view=$(echo $res | sed -r 's/.*<original_image>(.*)<\/original_image>.*/\1/') | |
delete=$(echo $res | sed -r 's/.*<delete_page>(.*)<\/delete_page>.*/\1/') | |
# Notify the user of completion | |
notify-send "gnome-screenshot-imgur" "$view" | |
# Copy URL to clipboard | |
echo $view | xsel --clipboard -ib | |
# Cleanup tmp file | |
rm $tmp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment