Skip to content

Instantly share code, notes, and snippets.

@SteveRyherd
Last active December 14, 2015 06:39
Show Gist options
  • Save SteveRyherd/5044126 to your computer and use it in GitHub Desktop.
Save SteveRyherd/5044126 to your computer and use it in GitHub Desktop.
Watches a directory for changes, when a new file is created or moved to the directory it is uploaded to imgur.com
#!/bin/bash
#
# imgurdrop
#
# Watches a folder (/tmp/imgur) for new files and uploads any new files
# in folder to imgur. The imgur URL will then appear in your clipboard.
#
# Intended to be used as a daemon, via dtach, screen, or simply "imgurdrop &"
#
# Originally inspired by:
# http://sirupsen.com/a-simple-imgur-bash-screenshot-utility/
#
# Dependencies:
#
# Xclip
# Comment: Xclip is what makes the script able to inject the direct url
# into your clipboard.
#
# libnotify*
# Comment: Will notify you whenever the direct URL is in the clipboard
#
# inotify-tools
# Comment: allows monitoring of the imgur drop directory
#
function uploadImage {
curl -s -F "image=@$1" -F "key=486690f872c678126a2c09a9e196ce1b" http://imgur.com/api/upload.xml | grep -E -o "<original_image>(.)*</original_image>" | grep -E -o "http://i.imgur.com/[^<]*"
}
mkdir /tmp/imgur 2>/dev/null
inotifywait -mqe create --format '%f' /tmp/imgur | while read file; do
url="$(uploadImage "/tmp/imgur/$file")"
echo $url | xclip -selection c
# If you prefer your notifications can use a static IMGUR logo icon.
# notify-send -u "low" -i "/usr/share/icons/notify-icons/imgur.png" -c "transfer.complete" "Upload Complete" "$url"
# Or a
notify-send -u "low" -i "/tmp/imgur/$file" -c "transfer.complete" "Upload Complete" "$url"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment