#!/bin/sh -
PATH=$PATH:/usr/bin/X11:/usr/openwin/bin

wdflt=1152
dirs="$HOME/share/arc/images $HOME/l/arc/images"

# kitty - set X11 background to kitty bitmap
# Steve Kinzler, steve@kinzler.com, Jun 93/Oct 97
# https://kinzler.com/me/home.html#x11
# https://kinzler.com/me/images/kitty_1024.xbm.Z
# https://kinzler.com/me/images/kitty_1152.xbm.Z
# https://kinzler.com/me/images/kitty_1280.xbm.Z

case "$1" in
-)	cmd=cat; shift;;
*)	cmd='xsetroot -bitmap';;
esac

case "$#,$1" in
0,)	w=`xwininfo -root | sed -n 's/^ *[Ww]idth: *\([0-9][0-9]*\) *$/\1/p'`
	case "$w" in
	'')	echo "$0: warning, cannot determine width, using default" 1>&2
		w=$wdflt;;
	esac;;

1,[0-9]*)	w="$1";;
*)		echo "usage: $0 [ - ] [ width ]" 1>&2; exit 1;;
esac

for dir in $dirs
do
	bm="$dir/kitty_$w.xbm.Z"
	test -f "$bm" && break
done

if test ! -f "$bm"
then
	echo "$0: warning, no image for width ($w), trying default" 1>&2
	for dir in $dirs
	do
		bm="$dir/kitty_$wdflt.xbm.Z"
		test -f "$bm" && break
	done
fi

tmp=/tmp/kitty$$
trap "rm -f $tmp; exit" 0 1 2 13 15

uncompress < "$bm" > $tmp && $cmd $tmp
