Skip to content

Instantly share code, notes, and snippets.

@fsmv
Last active December 27, 2015 21:39
Show Gist options
  • Save fsmv/7392978 to your computer and use it in GitHub Desktop.
Save fsmv/7392978 to your computer and use it in GitHub Desktop.
Set of scripts for a nice screenshot environment on linux Requires gnome-screenshot, notify-send, curl, and xclip Optionally depends on scrot for the scrn -s option
#On release because otherwise xbindkeys has problems with this command also using X at the same time
"scrn -a"
Release + Print
"scrn"
Release + Shift + Print
"scrn -s"
Release + Control + Print
#!/bin/bash
if [ $1 == '-s' ]
then
#In dwm gnome-screenshot -w doesn't work so I added this since scrot -s does
scrot -s /tmp/screenshot.png
else
gnome-screenshot $1 -f /tmp/screenshot.png
fi
uptoi /tmp/screenshot.png
rm /tmp/screenshot.png
#!/bin/bash
# imgur script by Phil Tang <tangphillip@gmail.com>
# Based the work of Bart Nagel <bart@tremby.net>
# Shared with a Creative Commons Attribution 3.0 Unported License.
############## Get your api key at http://api.imgur.com/ ################################
apikey="API KEY HERE"
#####################################################################################
CLIPBOARD=true
echo "Uploading $1"
# function to output usage instructions
function usage {
echo "Usage: $(basename $0) <filename>
Upload an image to imgur, print its URL to stdout, and print the delete page URL to stderr.
If you're on a Mac or have xsel/xclip, copy the image URL to the clipboard." >&2
}
# check API key has been entered
if [ "$apikey" = "Your API key" ]; then
echo "You first need to edit the script and put your API key in the variable near the top." >&2
exit 15
fi
# check arguments
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
usage
exit 0
elif [[ "$1" == "-x" || "$1" == "--no-clipboard" ]]; then
CLIPBOARD=false
shift
fi
if [ $# -ne 1 ]; then
if [ $# == 0 ]; then
echo "No file specified." >&2
else
echo "Unexpected arguments" >&2
fi
usage
exit 16
elif [ ! -f "$1" ]; then
echo "File \"$1\" not found" >&2
exit 1
fi
# check curl is available
which curl >/dev/null 2>/dev/null || {
echo "Couln't find curl, which is required." >&2
exit 17
}
# upload the image
response=$(curl -F "key=$apikey" -H "Expect: " -F "image=@$1" \
http://imgur.com/api/upload.xml 2>/dev/null)
# the "Expect: " header is to get around a problem when using this through the
# Squid proxy. Not sure if it's a Squid bug or what.
if [ $? -ne 0 ]; then
echo "Upload failed" >&2
exit 2
elif [ $(echo $response | grep -c "<error_msg>") -gt 0 ]; then
echo "Error message from imgur:" >&2
echo $response | sed -E 's/.*<error_msg>(.*)<\/error_msg>.*/\1/' >&2
exit 3
elif [[ "$response" != *original_image* ]]; then
echo "Unknown Failure: Imgur is probably down for maintenance."
exit 4
fi
# parse the response and output our stuff
url=$(echo $response | sed -E 's/.*<original_image>(.*)<\/original_image>.*/\1/')
deleteurl=$(echo $response | sed -E 's/.*<delete_page>(.*)<\/delete_page>.*/\1/')
echo $url
echo "Delete page: $deleteurl" >&2
export DISPLAY=:0.0
notify-send -i "$1" "Screenshot uploaded successfully." \
"Link copied to clipboard"
# put the URL on the clipboard if we have xsel or xclip
#if [ $DISPLAY -a $CLIPBOARD == true ]; then
# { which pbcopy >/dev/null 2>/dev/null && echo -n $url | pbcopy; } \
# echo -n $url | xsel
# || { which xclip >/dev/null 2>/dev/null && echo -n $url | xclip; } \
echo -n $url | xclip -selection c -d ":0.0"
# || echo "Haven't copied to the clipboard: no pbcopy, xsel, or xclip" >&2
#fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment