#!/bin/sh

# PURPOSE: Pipe stdin to web browser that doesn't support that directly.
#
# USAGE: Simply pipe to this script.  No arguments.
# 
# REQUIRES: A program in your path called "web" which accepts a
# file name to read as an argument.

if [ "$#" = 0 ]; then # no arguments
	progname="$(basename "$0")"
	tmpfile="$(mktemp -t "$progname".XXXXXXXXXX)".html || exit 1
	cat > "$tmpfile" # read stdin into temp file
	"$0" "$tmpfile" & # background ourselves to keep sleep from hanging caller
else # arguments
	web "$1"
	sleep 10 # give it time to load
	rm -f "$1"
fi
