#!/bin/sh -
user=kinzler
home=/home/$user
path=$home/binp:$home/bin:$home/bin/x86_64:$PATH
case "$1" in
-.)	exec echo 'unset HISTFILE histfile; clear;' \
		  "exec ~$user/binp/cshas -t $user";;
esac

# may be "." sourced or exec'ed or, eg:
#	alias k 'exec ~kinzler/binp/cshas'
#   or	alias k='exec ~kinzler/binp/cshas kinzler'
#   or	alias k 'exec ~kinzler/binp/cshas -t'
#   or	alias k 'exec ~kinzler/binp/cshas -t kinzler'
#   or	alias k='exec ~kinzler/binp/cshas -t kinzler'
# or in csh/tcsh/bash:
#	alias kinzler='exec ~kinzler/binp/cshas -t kinzler'
#	test -n "$shell" && alias kinzler 'exec ~kinzler/binp/cshas -t'
# or run output of `cshas -.`

xtitle=`PATH="$path" which xtitle`
cwdfile=.local/share/cwd

# cshas - run a login csh with the given user's environment
# Steve Kinzler, steve@kinzler.com, Aug 15
# https://kinzler.com/me/home.html#unix

case "$1" in
-t)	shift		# try to undo a window title change
	host=${HOST-${HOSTNAME-`(hostname) 2> /dev/null`}}
	host=`echo "$host" | sed 's/\..*//'`
	test -n "$host" && $xtitle -q "$host";;
esac

csh=`PATH="$path" which csh`
user="${USER-$LOGNAME}"
as="${1-${CSH_ENVIRON:-$user}}"

cwdf=`"$csh" -c "echo ~$as/$cwdfile"`
if test -s "$cwdf"
then
	cwd=`head -1 < "$cwdf"; : > "$cwdf"`
	test -x "$cwd" && cd "$cwd"
fi

ls > /dev/null || cd	# try to start in a directory we can read

exec "$csh" -c "setenv HOME_SU ~$user; setenv SHELL '$csh';
		set user = $as; set home = ~$as;
		source ~/.cshrc; source ~/.login; exec '$csh'"
# "csh -l" doesn't work everywhere
