X-Git-Url: https://git.slaskete.net/einar-bin/blobdiff_plain/6aa63624e9f9295b64c9bcd1b570fbcfff569f71..HEAD:/screenshot.sh?ds=inline diff --git a/screenshot.sh b/screenshot.sh index ec1931b..bf0999c 100755 --- a/screenshot.sh +++ b/screenshot.sh @@ -2,16 +2,20 @@ # A quick and dirty script to take a screenshot, upload it via scp # and put a link to it in the clipboard for easy pasting to i.e. IRC. # It assumes a lot of things, e.g. that ssh to the target host has -# been set up with a working private key, and that xclip and +# been set up with a working logon with private key, and that xclip and # gnome-screenshot is installed. # # If all you have is a hammer, everything looks like a nail. +# TODO: +# * Undo function +# * Check that we don't overwrite an existing file (theoretically possible, but unlikely) + # Settings RemoteUser="einar" RemoteHost="wowbagger.slaskete.net" RemotePath="/var/www/eina.rjh.im/screenshots/" -LocalPath="${HOME}/ownCloud/Screenshots/" +LocalPath="${HOME}/Pictures/Screenshots/" UrlBase="https://eina.rjh.im/g" function errcho() { @@ -19,14 +23,20 @@ function errcho() { } function take_screenshot() { - FileName="$(tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 6 | head -n 1).png" - if [ "$@" = "clipboard" ]; then + FileID="$(tr -dc 'a-zA-Z0-9' < /dev/urandom | fold -w 6 | head -n 1)" + FileName="${FileID}.png" + if [ "$*" = "clipboard" ] || [ "$*" = "jpg" ]; then xclip -out -selection clipboard -t image/png > "/tmp/${FileName}" 2>/dev/null - if [ "$(file -b --mime-type /tmp/${FileName})" == "image/png" ]; then + if [ "$(file -b --mime-type "/tmp/${FileName}")" == "image/png" ]; then + if [ "$*" = "jpg" ]; then + convert "/tmp/${FileName}" "/tmp/${FileID}.jpg" + rm "/tmp/${FileName}" + FileName="${FileID}.jpg" + fi mv "/tmp/${FileName}" "${LocalPath}/" else rm "/tmp/${FileName}" - notify-send -i applets-screenshooter "screenshot.sh" "Tried to post image from clipboard, but found no image there." + notify-send -a "screenshot.sh" -i dialog-warning "Ooopsie" "Tried to post image from clipboard, but found no image there." fi else gnome-screenshot -f "${LocalPath}/${FileName}" -p "$@" @@ -35,19 +45,29 @@ function take_screenshot() { scp -q "${LocalPath}/${FileName}" "${RemoteUser}@${RemoteHost}:${RemotePath}" echo -n "${UrlBase}/${FileName}"|xclip -selection p echo -n "${UrlBase}/${FileName}"|xclip -selection c - notify-send -i applets-screenshooter "screenshot.sh" "Screenshot published to ${UrlBase}/${FileName}" + notify-send -a "screenshot.sh" -i applets-screenshooter "Screenshot uploaded" "Screenshot published to ${UrlBase}/${FileName}" fi } -function show_error() { - errcho "Please use one of: -w, --window, -a, --area, -s, --selection," - errcho " -f, --full or no argument at all." +function show_help() { + errcho "Usage: screenshot.sh [option]" + errcho "This script wraps gnome-screenshot in order to instantly upload screenshots and get back a URL for sharing to IRC or other social media" + errcho "The default option is to take a screenshot of the whole screen." + errcho "The following options are available:" + errcho "-f, --full Take screenshot of the whole screen" + errcho "-w, --window Take screenshot of the active window" + errcho "-a, --area Take screenshot of an area/selection" + errcho "-s, --selection Take screenshot of an area/selection" + errcho "-c, --clipboard Upload image from paste buffer if present" + errcho "-p, --paste Upload image from paste buffer if present" + errcho "-j, --jpg, --jpeg Convert image from paste buffer to jpeg and upload" + errcho "-h, --help Show this help" exit 1 } case ${1} in -w|--window) - take_screenshot -w -b -e shadow + take_screenshot -w -b ;; -a|--area|-s|--selection) sleep 0.2 @@ -59,8 +79,15 @@ case ${1} in -c|--clipboard|-p|--paste) take_screenshot clipboard ;; + -j|--jpg|--jpeg) + take_screenshot jpg + ;; + -h|--help) + show_help + ;; *) - show_error + errcho "ERROR: Unknown option." + show_help ;; esac