# $Id: dot-kshrc,v 2.0 1994/02/26 20:40:24 jimt Exp $

## This file contains a sample script showing how to set up ksh to
## work properly with j-shell.  Before examining this script, please
## read the comments in the file dot-tcsh; the comments in that script
## describe steps common to the scripts for all shells.

# Comments delimited by a single # are specific to ksh.

if [ "$TERM" = "emacs" ]
then
	stty nl -echo		# Keeps ^M from echoing

	## Step A.
	emacscd="\033EmAcScd"
	emacshost="\033EmAcShost"
	emacsenv="\033EmAcSenv"

	## Step B.
	# Note that we have to use a function instead of an alias in
	# ksh; an alias doesn't seem to work.
	cwdcmd() { echo $emacscd $PWD ; }
	hostcmd() { echo $emacshost `hostname` ; }

	reenv()
	{
	  for f in [ `env` ]
	  do
	    echo $emacsenv $f
	  done
	}

	if [ $REORIENT_ENV ]
	then
		reorient() { hostcmd ; cwdcmd ; reenv ; }
	else
		reorient() { hostcmd ; cwdcmd ; }
	fi

	## Step C.
	# In ksh, it seems that an alias can't reference the command
	# that it is replacing, as it can in csh.  Thus, we need two
	# steps to redefine cd and the like.  Also note that ksh has
	# no pushd and popd to redefine.
	fake_cd() { cd $* ; cwdcmd ; }
	alias cd=fake_cd

	## Step C-2.
	if [ $SYNC_ENV ]
	then
		fake_export() { export $* ; echo $emacsenv $* ; }
		alias export='fake_export'
	fi

	## Step D.
	fake_rlogin() { rlogin $*; reorient ; }
	alias rlogin='fake_rlogin '

	fake_sh() { sh $*; reorient ; }
	alias sh=fake_sh

	fake_ksh() { ksh $*; reorient ; }
	alias ksh=fake_ksh

	fake_csh() { csh $*; reorient ; }
	alias csh=fake_csh

	fake_tcsh() { tcsh $*; reorient ; }
	alias tcsh=fake_tcsh

	fake_zsh() { zsh $*; reorient ; }
	alias zsh=fake_zsh

	fake_bash() { bash $*; reorient ; }
	alias bash=fake_bash

	fake_tcl() { tcl $*; reorient ; }
	alias tcl=fake_tcl

	## Step E.
	reorient
fi
