# prototype profile for msh.prg 3.0 release (hard disk)
#
# First order of business: set the environments which the shell uses
# to find commands and create temporary files.
#
# Note that .bin does not need to be listed in PATH.
#
# Since you can rename any function in .bin, eg
#	set in .bin dir=${.bin\ls}
#	unset in .bin ls
# there really isn't any need to put it in the PATH.
# .bin is now always searched first, and the only .bin names
# which are wired into the shell are 'set' and ''.

set drive1=$cwdisk:				# get the "boot" drive
set ramdrive=h:					# a ram-disk here?
setenv PATH=.cmd,,$drive1\mwc\bin,$drive1\mwc\lib	# set the cmd search path
setenv SUFF=,.prg,.ttp,.tos			# executable file suffixes
setenv LIBPATH=$drive1\mwc\lib,$drive1\mwc\bin,		# library search path
setenv INCDIR=$drive1\mwc\include			# directory for include files
setenv TIMEZONE=PST			# this is the Central time zone

# Set up TMPDIR.
# This directory is used by the shell when evaluating 
# `commands` substitutions, so the `getrez` and `getpal`
# below will fail if TMPDIR does not exist or TMPDIR is
# not defined and the default TMPDIR, \tmp, does not exist.
# We check to see if a RAM disk is installed (ramdrive, set above)
# and if it is, we put the tmp directory there, otherwise, we use
# the default drive.
if (drvprs -q $ramdrive) (
	setenv TMPDIR=$ramdrive\tmp		# ramdisk present
	mkdir $TMPDIR				# create tmp directory
) (
	setenv TMPDIR=$drive1\mwc\tmp		# else, use default disk
)

# The home directory is used by some commands for default actions,
# for example, the `cd' command with no arguments sets your default
# directory to HOME.
setenv HOME=$drive1\			# your directory here

# Now we change the screen to a TOS style display.
# You can change this stuff if you like.
# This particular setup duplicates what the previous
# versions of msh did internally, but it reverses
# the video to white on black to reduce screen burn-in.

hidemouse			# turn off the mouse cursor
setenv ESC=''			# that's an escape character hiding in there
echo -n ${ESC}E${ESC}e${ESC}v	# clear screen, text cursor on, line wrap on
setenv DEFREZ=`getrez`		# fetch the screen resolution
# the double quotes keep the palette from being split into separate words.
setenv DEFPAL="`getpal`"	# and the screen palette
setenv MSHREZ=$DEFREZ		# initialize our own resolution
setenv MSHPAL="$DEFPAL"		# and our own palette

# note that unlike most shells, the 'if' command is being parsed just like
# any other command.  It is the open parenthesis after the if ( expression )
# which continues the command to the next line.  If you wrote:
#	if (equal $DEFREZ 0)
#		( ... )
# you would get a usage message from 'if' complaining about the missing
# argument, and the shell would run ( ... ) as a separate command.

if (equal $DEFREZ 0) (		# if we're in low resolution
	setenv MSHREZ=1
	setrez $MSHREZ			# go to medium resolution
	setenv MSHPAL="0 0 0 0x777"
	setpal $MSHPAL			# and reverse video
)
if (equal $DEFREZ 2) (		# if we're in high resolution
	setenv MSHPAL=0
	setpal $MSHPAL			# just reverse video
)

# Miscellaneous settings

# the single quotes keep the $cwdisk from being expanded until
# the prompt is evaluated.  otherwise you get the boot drive.
# below are two different prompts, if you want the '$' prompt,
# don't set prompt at all, or do an "unset prompt".
set prompt='$cwd % '		# a dos style current drive prompt
set history=8			# number of lines of history to keep

# the pwd builtin is once again built-in

# gemset hacks the screen back to the state it was in when we were
# launched by the desktop.  Gem/Aes/Vdi is not amused by secret
# resolution or palette changes.
set in .cmd gemset=(
	echo -n ${ESC}f		# text cursor off
	setrez $DEFREZ		# reset resolution
	setpal $DEFPAL		# reset palette
	showmouse		# mouse cursor on
)

# The reverse of gemset to restore us to shell configuration
set in .cmd mshset=(
	hidemouse		# mouse cursor off
	setrez $MSHREZ		# shell resolution
	setpal $MSHPAL		# shell palette
	echo -n ${ESC}E${ESC}e${ESC}v
)

# gem used to be a wired builtin function, now we can write it as a command.
set in .cmd gem=(
	gemset			# set gem screen
	$* 2>aux: >con: <con:	# execute the command
	set t=$status		# get the exit status of $*
	mshset			# restore shell screen
	exit $t			# return the status
)

# the tos builtin is simple:  just make sure the standard handles
# point to the default places, or point them someplace else if
# you like.  You might try 3>aux: if you can't get a serial printer
# to work any other way.
set in .cmd tos=( $* 2>aux: >con: <con: )

# here's an example of argument list processing.  display simply prints
# it's arguments with a label one to a line.

set in .cmd display=(
	while (is_set in argv 1) ( echo argument: $1; unset in argv 1 )
)

# some people find that the history mechanism is difficult to use, and
# that much of this difficulty comes from having to type "set in history"
# to view this history.  The following adds the command "hist" to show
# the history.

set in .cmd h=(set in .msh\.msh\history)

# finally, a way to use make if you run out of memory trying to use it
# normally.  'make -n' generates the list of commands needed onto standard
# output, so we catch them in a file and have the shell execute them
# directly.  The only problem is that the shell doesn't quit when one of
# them fails.

set in .cmd mymake="make -n > mscript; set verbose; . mscript; unset verbose"

# This command will fetch the keyboard clock and use it to initialize
# both the mwc library time() function and the gemdos date and time functions.
# This will keep the time up to date across a warm start so you only need to
# set it by hand when you power up.

date `date -i`

# put the postfile into .cmd for less trouble
set in .cmd postfile=(
	echo -n ${ESC}f		# text cursor off
	setrez $DEFREZ		# reset the resolution
	setpal $DEFPAL		# reset the palette
	showmouse		# mouse cursor on, but the desktop forces it
)

cd
