# Global cshrc file
#
# $Id: cshrc,v 1.11 2005/05/31 14:13:14 rbasch Exp $

# This file is sourced by default user file ~/.cshrc


set initdir=/usr/athena/lib/init

# *******************   ENVIRONMENT SETUP   *******************

# Compatibility with older versions of Athena tcsh
set autolist=""
if ($?tcsh) then
  bindkey "^W" backward-delete-word
  bindkey "^Z" complete-word
  bindkey " " magic-space

  if ($tcsh:r:e > 7 || $tcsh:r:r > 6) then
    alias bind 'echo The \"bind\" command is no longer supported in tcsh 6.08. Use the; echo \"bindkey\" command instead. See the tcsh man page for more information.; ( echo \!* > /dev/null )'
  endif
endif

# Set host type and hostname variables.
if (! $?ATHENA_HOSTTYPE) setenv ATHENA_HOSTTYPE "`/bin/athena/machtype`"
if (! $?HOST) setenv HOST "`hostname`"
setenv HOSTTYPE "$ATHENA_HOSTTYPE"
set hosttype=$HOSTTYPE
set host=$HOST

switch ("$HOSTTYPE")
case sun4:
  set athena_path=( /srvd/patch /usr/athena/bin /usr/athena/etc /bin/athena \
		    /usr/openwin/bin /usr/openwin/demo /usr/dt/bin /usr/bin \
                    /usr/ccs/bin /usr/sbin /sbin /usr/sfw/bin /usr/ucb )
  set athena_manpath=/usr/athena/man:/usr/openwin/man:/usr/dt/man:/usr/man
  set athena_manpath=${athena_manpath}:/usr/sfw/man
  breaksw
case linux:
  set athena_path=( /usr/athena/bin /usr/athena/etc /bin/athena /usr/bin \
		    /bin /usr/X11R6/bin /usr/sbin /sbin )
  set athena_manpath=/usr/athena/man:/usr/share/man:/usr/X11R6/man
  breaksw
default:
  echo "Standard dotfiles do not support system type $HOSTTYPE."
  breaksw
endsw

# Set up standard system/user environment configuration (including setup of
# environment variables, attachment of lockers, and setting of search path)

if (! $?ENV_SET) then

  setenv ENV_SET				# Avoid unnecessary repeat

  umask 077				# Strictly protect files
					#  (does not apply in AFS)
  limit coredumpsize 0            	# Don't allow coredumps
  setenv MORE -s			# Default "more" behavior
					# we are now down to -s
					# because -d is wrong.
  setenv EDITOR emacs			# Set default editor
  setenv VISUAL emacs			# Set default screen editor
  setenv MM_CHARSET iso-8859-1

  # Set standard Athena path variables.  Actual $path (and thus $PATH)
  # are set later, after ~/.environment is sourced.

  setenv MANPATH "$athena_manpath"

  # Set other miscellaneous OS-specific environment variables
  switch ("$HOSTTYPE")
  case sun4:
    setenv OPENWINHOME /usr/openwin
    breaksw
  case linux:
    # This is to ensure that native programs use the Athena gconf, ORBit,
    # bonobo-activation, etc. libraries rather than the native ones.
    # GNOME programs outside of /usr/athena/bin may not function properly
    # if it is not set.
    setenv LD_LIBRARY_PATH /usr/athena/lib
    breaksw
  endsw

  setenv ATHENA_SYS `/bin/athena/machtype -S`
  if ( $ATHENA_SYS == "" ) then
    setenv ATHENA_SYS @sys
  endif
  setenv ATHENA_SYS_COMPAT `/bin/athena/machtype -C`

  set bindir=arch/${ATHENA_SYS}/bin

  if ( ! $?PRINTER && -e /var/athena/clusterinfo ) then
    setenv PRINTER `awk '/LPR/ { print $3 }' /var/athena/clusterinfo`
    if ( $PRINTER == "" ) unsetenv PRINTER
  endif

  setenv XDG_DATA_DIRS /usr/athena/share:/usr/share

  # Reset the "home" and HOME variables to correspond to the actual
  # location of the user's home directory.  This will avoid having
  # long pathnames being printed when /mit/<user> is a symlink to a
  # path within AFS.
  #
  # This code has been optimized to run as quickly as possible.  Since
  # it is being invoked only at the beginning of the session, and
  # prior to the inclusion of any of the user's other dotfiles, we can
  # assume that the current directory is the user's home directory.
  # Also, to avoid having the shell re-evaluate the current contents
  # of the directory, we help it by resetting its "cwd" variable.  We
  # do error checking just in case the path somehow disappears.

  set x=`/bin/pwd`
  if ("$x" != "") then
    set home=$x cwd=$x
  endif
  unset x

  # Special version of add alias that will work in your ~/.environment
  # file.  This is replaced further down with the version that works
  # when you are logged in.

  # This "extend" alias and friends have been left in for backwards
  # compatibility with old .environment files, just in case. The new
  # add alias does not use them.
  alias extend 'if (-d \!:2) if ("$\!:1" \!~ *"\!:2"*) set extendyes && \\
  if ($?extendyes && $?verboseadd) echo \!:2 added to end of \$\!:1 && \\
  if ($?extendyes) setenv \!:1 ${\!:1}:\!:2 && \\
  unset extendyes'
  alias sextend 'if (-d \!:2) if ("$\!:1" \!~ *"\!:2"*) set extendyes && \\
  if ($?extendyes && $?verboseadd) echo \!:2 added to end of \$\!:1 && \\
  if ($?extendyes) set \!:1=(${\!:1} \!:2) && \\
  unset extendyes'
  alias textend 'if (-d \!:2) if ("$\!:1" \!~ *"\!:2"*) set extendyes && \\
  if ($?extendyes && $?verboseadd) echo \!:2 added to end of \$\!:1 && \\
  if ($?extendyes) set \!:1=${\!:1}:\!:2 && \\
  unset extendyes'

  alias add 'eval `/bin/athena/attach -Padd -P "$athena_path" \!:*`'

  # Run user environment customizations identified in your
  # ~/.environment file.  This is the place to include your own
  # environment variables, attach commands, and other system wide
  # setup commands.  You can also cancel default behaviors listed
  # above with "unsetenv" or "setenv".  ~/.environment is not sourced
  # if NOCALLS is set (i.e., if you selected the xlogin "Ignore your
  # customizations" option when you logged in).

  if ((! $?NOCALLS) && (-r ~/.environment)) source ~/.environment
	
  # remove temporary version of add
  unalias extend sextend textend add
  alias add 'echo Use add in your ~/.environment, not your ~/.path.'

  # Reset athena_manpath in case .path uses it (.path should just use
  # $MANPATH, but using $athena_manpath has worked historically).
  set athena_manpath=$MANPATH

  # Set up default search path, if not yet set.  Use your ~/.path file
  # to provide an alternative path -- this file should be of the form
  # "set path=...", and can refer to the shell variable $athena_path,
  # defined above. The ~/.path file should list a complete path, since
  # the path identified there will be used INSTEAD of the default
  # path, not appended.  ~/.path is not sourced if the xlogin "Ignore
  # your customizations" option was selected to begin the session.

  if ((! $?NOCALLS) && (-r ~/.path)) then
    # User-specified path
    source ~/.path
  else
    # Standard Athena path
    set path=(`/usr/athena/bin/athdir $HOME` $athena_path .)
  endif

  # Make sure applications can properly find their appdefs, etc.

  if (! $?XUSERFILESEARCHPATH) then
    setenv XUSERFILESEARCHPATH "/usr/athena/lib/X11/app-defaults/%N"
  else
    setenv XUSERFILESEARCHPATH "${XUSERFILESEARCHPATH}:/usr/athena/lib/X11/app-defaults/%N"
  endif
endif

# Set appropriate bin directory variable for this platform
# (e.g., vaxbin for VAXstations, decmipsbin for pMAXen, etc.;  this will
# be included in actual searchpath as ~/$bindir -- e.g., ~/vaxbin):
set bindir=arch/${ATHENA_SYS}/bin

# *******************  C SHELL SETUP   *******************

# Set up standard C shell initializations

set noclobber			# Don't overwrite files with redirection

if ($?prompt) then		# For interactive shells only (i.e., NOT rsh):
  # Set prompt.
  set promptchars="%#"
  if ($home =~ /var/athena/tmphomedir/*) then
    set prompt = "linerva (temporary homedir)%# "
  else
    set prompt = "linerva%# "
  endif

  set cdpath = (~)		#   Path to search for directory changes
  set interactive		#   Provide shell variable for compatability
  set nostat = (/afs/)		#   Don't stat when completing in /afs
endif

# Set up standard C shell aliases

#   alias for re-establishing authentication
alias renew 'kinit $USER && fsid -a && zctl load /dev/null'

#   alias for a convenient way to change terminal type
alias term 'set noglob; unsetenv TERMCAP; eval `tset -s -I -Q \!*`'

#   aliases dealing with x window system
alias xresize 'set noglob; eval `resize -c` || unset noglob'

if ($?XSESSION) then
  if ("$XSESSION" == "") then
    alias logout	'exit && end_session'		# logout for X
  else
    alias logout	'exit && kill -HUP $XSESSION'	# logout for X
  endif
endif

#   aliases dealing with adding locker programs
#   extend remains for other software; add no longer uses the extend alias
alias extend 'if (-d \!:2) if ("$\!:1" \!~ *"\!:2"*) set extendyes && \\
	if ($?extendyes && $?verboseadd) echo \!:2 added to end of \$\!:1 && \\
	if ($?extendyes) setenv \!:1 ${\!:1}:\!:2 && \\
	unset extendyes'

set add_flags
alias add 'eval `/bin/athena/attach -Padd $add_flags \!:*`'

#   aliases dealing with subjects
alias setup_X '( setenv SUBJECT \!:1 ; ( xterm -title \!* & ) )'
alias setup_tty '( setenv SUBJECT \!* ; $SHELL )'
if ($?XSESSION) then
  alias setup setup_X
else
  alias setup setup_tty
endif
alias remove 'setenv SUBJECT \!* ; source $initdir/env_remove'

# If this is a subject window, run the env_setup script
if (($?SUBJECT) && (-r $initdir/env_setup)) source $initdir/env_setup


# All of the C shell initializing commands above can be overridden by
# using "unset" or "unalias" commands (or by changing things using
# "set" or "alias" again) in your ~/.cshrc.mine file, which is sourced
# here.  ~/.cshrc.mine is not sourced if the xlogin "Ignore your
# customizations" option was selected to begin the session.

if ((! $?NOCALLS) && (-r ~/.cshrc.mine)) source ~/.cshrc.mine
