#!/bin/sh
#
# screenshot -- a ridiculously simple frontend to xwd, best suited for
#               calling from your window manager.
#
#               for example, i used WPrefs to make WindowMaker take a 
#               full screen shot on PrintScreen and allow me to select
#               a window for a single screen shot (screenshot -i ) on 
#               Shift+PrintScreen.  does anybody know how to get the
#               current window ID out of windowmaker?
#
#               if you don't like subsequent processing with gimp or xv
#               or [your favorite gfx app] then add in a call to convert
#               or something.
#
# muppet, 22 november 1999
#

XWDOPT=-root

while [ $# -ne 0 ] ; do
	case $1 in
		-i)	# interactive, select window with mouse
			XWDOPT="-frame"
			;;
		-h)	# help me!
			echo "screenshot -- take a screenshot, duh..."
			echo "usage: screenshot [-i] [filename]"
			echo "    -i        interactive mode (select window with mouse)."
			echo "              default is to take the root window."
			echo "    filename  save xwd dump to given filename."
			echo "              default is to create a temp name of the"
			echo "              form '~/xwd.'something."
			exit
			;;
		*)	# assume output file name
			OUTFILE=$1
			break
			;;
	esac
	shift
done

if [ -z "$OUTFILE" ] ; then
	OUTFILE=`mktemp $HOME/xwd.XXXXXX`
	if [ -z "$OUTFILE" ] ; then
		OUTFILE="$HOME/xwd."`date +"%Y%m%d%H%M%S"`
	fi
fi

xwd $XWDOPT > $OUTFILE
