#!/bin/sh

#
# Make screen shoot, of window or full screen
# need ImageMagic
#
# Version: 20090827.1
#
# «THE BEER-WARE LICENSE» (Revision 42):
# hatred@inbox.ru wrote this file. As long as you retain
# this notice you can do whatever you want with this stuff.
# If we meet some day, and you think this stuff is worth it,
# you can buy me a beer in return. Alexander 'hatred' Drozdoff 
#


TYPE="png"
image="$HOME/screen_shoot-`date +%Y%m%d-%R:%S`.$TYPE"

# Default settings
DELAY=0
SCRTYPE=window # full | window | window_frame
VIEW=0

# Parse command line
CMD="$*"
cont=0
prev=""
for i in $CMD
do
    if [ $cont -eq 1 ]; then
        cont=0
        case $prev in
            -d) DELAY=$i
        esac
        continue
    fi

    prev=$i
    case $i in
        -d)  cont=1;;
        -f)  SCRTYPE=full;;
        -w)  SCRTYPE=window;;
        -wf) SCRTYPE=window_frame;;
        -v)  VIEW=1;;
        --help) echo "shoot.sh [-d <delay>] [-f|w|wf ] [-v] [--help]"
                echo "  -d <delay> - pause"
                echo "  -f         - full screen shoot"
                echo "  -w         - window shoot"
                echo "  -wf        - window shoot with frame"
                echo "  -v         - view after shoot"
                echo "  --help     - this help"
                exit 0;;
    esac

done


case $SCRTYPE in
    full)
    	sleep $DELAY
	import -window root $image
	;;
    window)
    	import -pause $DELAY $image;;
    window_frame)
    	import -pause $DELAY -frame $image;;
esac

if [ $VIEW -eq 1 ]; then
    geeqie $image
fi

