#! /bin/sh
T="`echo x | tr x '\011'`"
MINUS=""
LOADFILE=""
INTERACT=""
CSH=csh
case "$ZSH_NAME$ZSH_VERSION$VERSION" in
zsh*)
case $1 in
-l*) MINUS="-" ;;
-i*) INTERACT="-i" ;;
*) LOADFILE="source $1" CSH="csh -f";;
esac
if [[ -o INTERACTIVE ]]; then INTERACT="-i"; fi
setopt nobanghist
;;
*)
case $1 in
-l*) LOADFILE="source ~/.login" ;;
-i*) INTERACT="-i" ;;
*) LOADFILE="source $1" CSH="csh -f";;
esac
;;
esac
( eval $MINUS $CSH $INTERACT ) <<EOF 2>&1 >/dev/null
$LOADFILE
alias >! /tmp/cz$$.a
setenv >! /tmp/cz$$.e
set >! /tmp/cz$$.v
EOF
exec 9<&0
exec < /tmp/cz$$.a
sed -e 's/'"$T"'(\(.*\))/'"$T"'\1/' >/tmp/cz$$.1
grep ! /tmp/cz$$.1 >/tmp/cz$$.2
grep -v ! /tmp/cz$$.1 >/tmp/cz$$.3
sed -e "s/'/'"\\\\"''"/g \
-e 's/^\([^'"$T"']*\)'"$T"'\(.*\)$/alias -- \1='"'\2'/" \
/tmp/cz$$.3
sed -e 's/>\(&*\)!/>\1|/g' \
-e 's/!\*:q/"$@"/g' \
-e 's/\(![: -e 's/!\([-0-9][0-9]*\)\(:x\)*/$\2(fc -nl \1)/g' \
-e 's/\$:x(fc/$=(fc/g' \
-e 's/![: -e 's/\$=\(=[^'"$T"']*\):x/$\1/g' \
-e 's/\$cwd/$PWD/' \
-e 's/^\([^'"$T"']*\)'"$T"'\(.*\)$/\1 () { \2 }/' \
/tmp/cz$$.2
exec < /tmp/cz$$.e
sed -e '/^SHLVL/d' \
-e '/^PWD/d' \
-e '/^_=/d' \
-e "s/'/'"\\\\"''"/g \
-e "s/^\([A-Za-z0-9_]*=\)/export \1'/" \
-e "s/$/'/"
exec < /tmp/cz$$.v
sed -e 's/'"$T"'/=/' \
-e "s/'/'"\\\\"''"/g \
-e '/^[A-Za-z0-9_]*=[^(]/{
s/=/='"'/"'
s/$/'"'/"'
}' |
sed -e '/^argv=/d' -e '/^cwd=/d' -e '/^filec=/d' -e '/^status=/d' \
-e '/^autolist=/s/.*/setopt autolist/' \
-e '/^correct=all/s//setopt correctall/' \
-e '/^correct=/s//setopt correct/' \
-e '/^histchars=/s//HISTCHARS=/' \
-e '/^history=/s//HISTSIZE=/' \
-e '/^home=/s//HOME=/' \
-e '/^ignoreeof=/s/.*/setopt ignoreeof/' \
-e '/^noclobber=/s/.*/setopt noclobber/' \
-e '/^notify=/d' \
-e '/^prompt=/s/!/%h/' \
-e 's/^prompt/PROMPT/' \
-e '/^showdots=/s/.*/setopt globdots/' \
-e '/^savehist=/s//HISTFILE=\~\/.zhistory SAVEHIST=/' \
-e '/^who=/s//WATCHFMT=/'
exec 0<&9
rm /tmp/cz$$.?
exit