#!/bin/sh
#
# A front end for running X programs from the window manager. We can do
# centralized housekeeping here, and also keep the window manager config.
# file cleaner.
#
# This is run from twm menus to start programs, to keep the twmrc clean
#
# Hannu Aronsson <haa@hutcs.hut.fi>
#

PATH="${PATH}:/p/bin:/bin:/usr/bin:/usr/ucb"

# If user has his/her own .xstart, run it instead. The -users_own flag will
# be given when the script is run from the user's home directory to avoid
# looping. You can delete the following if-statements if you copy this into
# your home directory.
# 
if [ "X$1" = "X-users_own" ]	# Avoid looping again and again to the user's
then				# .xstart
  shift
else
  if [ -f $HOME/.xstart ]
  then
	exec /bin/sh $HOME/.xstart -users_own "$@"
	echo "The .xstart in your home directory $HOME cannot be run." >&2
  fi
fi

Usage="$0 identifier [options]"

prog="$1"			# Argument checking should be better
shift
rest="$*"

case "$prog" in
  xterm)		# Just an ordinary xterm
	xterm $rest &
	;;
  xtermcmd)		# An xterm with a command
	xterm -T "$rest" -e $rest &
	;;
  xtermrsh)		# An xterm with a remote login
	xterm -T "$rest" -e rsh $rest &
	;;

  cmd)			# Any command
	$rest &
	;;
  xman|xcalc|puzzle|xchess|xload|xlogo)	# one of these commands
	$prog $rest &
	;;

  elm)			# An xterm containing the Elm mailer
	xterm -T "Electronic mail -- Elm" -e /bin/sh -c 'elm; sleep 4' &
	;;
  emacs)		# GNU Emacs
	if sps 2>/dev/null | grep -s '[0-9] emacs' >/dev/null 2>&1
	then
		emacs &	# Ordinary emacs
	else
		emacs -geometry 80x55-10-15 & # First, large window emacs
	fi
	;;
  windowdump)
	#xwd -xy | xpr -compact -device ps | rsh sauna lpr -Paw &
	xwd -xy | xwdlbp &
	;;
  *)	echo $Usage >&2
	;;
esac

#eof
