diff --git a/glue/src/screenshot b/glue/src/screenshot index d056aea..dbcbdde 100755 --- a/glue/src/screenshot +++ b/glue/src/screenshot @@ -1,35 +1,58 @@ #!/bin/sh -if ! type scrot > /dev/null; then - >&2 echo "!!! scrot is not installed" - exit 1 -fi +name=`basename "$0"` + +isInstalled() { + type "$1" > /dev/null +} + +mustHaveInstalled() { + if ! isInstalled "$1"; then + echo "$name: $1 is not installed" >&2 + exit 1 + fi +} + +usage() { + echo "Usage: $name [selection | window | screen] [clipboard]" >&2 + exit 2 +} picturesDir=`xdg-user-dir PICTURES` test -z "$picturesDir" && picturesDir="$HOME/Pictures" picturesDir="$picturesDir/Screen Shots" if ! mkdir -p "$picturesDir"; then - >&2 echo "!!! can't create $picturesDir" + echo "$name: can't create $picturesDir" >&2 exit 1 fi -output="$picturesDir/`date -Iseconds`.png" +outputFilePath="$picturesDir/`date -Iseconds`.png" +mustHaveInstalled scrot case "$1" in -"selection") - scrot --select --line style=dash --freeze --file "$output" - clipArg="$2" - ;; -"window") - scrot --focused --border --file "$output" - clipArg="$2" +"selection" | "window" | "screen") + mode="$1" + shift 1 ;; *) - scrot --file "$output" - clipArg="$1" + mode="screen" ;; esac -if test "$clipArg" = "clipboard"; then - xclip -selection clipboard -target image/png -i "$output" +if [ "$1" = "clipboard" ]; then + clipboard=true + shift 1 +fi + +[ "$#" -gt 0 ] && usage + +case "$mode" in +"selection") scrot --select --line style=dash --freeze --file "$output";; +"window" ) scrot --focused --border --file "$output";; +"screen" ) scrot --file "$output";; +esac + +if [ -n "$copyToClipboard" ]; then + mustHaveInstalled xclip + xclip -selection clipboard -target image/png -i "$outputFilePath" fi