#!/usr/bin/env zsh

# $Id: zshenv,v 1.5 2003/10/08 10:40:40 dave Exp $

#export MANPATH=$MANPATH:/usr/local/man
rationalize-path () {
    local element
    local build
    build=()
    eval '
    foreach element in "$'"$1"'[@]"
    do
	if [[ -d "$element" ]]
	then
	    build=("$build[@]" "$element")
	fi
    done
    '"$1"'=( "$build[@]" )
    '
}

zsh-version ()
{
    if [[ ${+zshversioncache} -eq 1 && ${+zshversioncache[$1]} -eq 1 ]]
    then
	return $zshversioncache[$1]
    fi

    local running
    local wanted

    running=(${(s:.:)ZSH_VERSION})
    wanted=(${(s:.:)1})

    while [[ $#running -gt 0 ]]
    do
	if [[ $running[1] -lt $wanted[1] ]]
	then
	    if [[ ${+zshversioncache} -eq 1 ]]
      then
         zshversioncache[$1]=1
      fi
      return 1    # Failure, want more recent than we have
    elif [[ $running[1] -gt $wanted[1] ]]
    then
      if [[ ${+zshversioncache} -eq 1 ]]
      then
         zshversioncache[$1]=0
      fi
      return 0    # Success, running newer version
    else
      shift running  # Look at next part of version
      shift wanted
    fi
  done
  if [[ $#wanted -gt 0 ]]
  then
    if [[ ${+zshversioncache} -eq 1 ]]
    then
       zshversioncache[$1]=1
    fi
    return 1  # Failure, wanted version has an extra part and is thus later
  else
    if [[ ${+zshversioncache} -eq 1 ]]
    then
       zshversioncache[$1]=0
    fi
    return 0  # Exactly the same version
  fi
}
if zsh-version 3.1.6
then
  # Associative arrays are available.
  typeset -A zshversioncache
  zshversioncache=( )
fi


    
if [[ $ZSH_VERSION == 3.0.<->* ]]; then ZSH_STABLE_VERSION=yes; fi
if [[ $ZSH_VERSION == 3.1.<->* ]]; then ZSH_DEVEL_VERSION=yes;  fi

ZSH_VERSION_TYPE=old
if [[ $ZSH_VERSION == 3.1.<6->* ||
      $ZSH_VERSION == 3.<2->.<->*  ||
      $ZSH_VERSION == 4.<->* ]]
then
  ZSH_VERSION_TYPE=new
fi

###############
# Paths for zsh

cdpath=( . )
export CDPATH
typeset -U cdpath

fpath=( $HOME/lib/zsh/func /usr/share/zsh/site-functions "$fpath[@]" )
export FPATH
typeset -U fpath

path=(
    "$HOME/bin/$MACHTYPE=$OSTYPE"
    "$HOME/bin"
    "$HOME/build/mozilla/dist/bin"
    /opt/bin
    /usr/exim/bin
    "$HOME/mozilla"
    /usr/local/bin
    /usr/local/sbin
    /sbin
    /bin
    /usr/bin
    /usr/sbin
    /usr/X11R6/bin
    /usr/bin/X11
    /usr/games
    /usr/local/netscape
    "$path[@]"
    "$fpath[@]"
)
export PATH
typeset -U path
rationalize-path path

# Mail folders
mailpath=(
"/var/spool/mail/$LOGNAME?You have new mail in /var/spool/mail/dave"
)
export MAILPATH

for paths in "$fpath[@]"
do
    if zsh-version 3.1.6
    then
	autoload -U "$paths"/*(N:t) > /dev/null
    else
	autoload "$paths"/*(N:t) > /dev/null
    fi
done
unset paths

READNULLCMD=cat
NULLCMD=cat


if [[ $TERM == 'xterm' ]]
then 
    export TERM=xterm-color
fi

if [[ $TERM_PROGRAM == "Apple_Terminal" ]]
then
    if [[ $TERM == "screen" ]] {
      unset TERM_PROGRAM; export TERM_PROGRAM
    } else {
      if [[ -z $DISPLAY ]] {
          export TERM=vt100-color
      }
    }
fi

if [[ $TERM == "xterm-color" || $TERM_PROGRAM = "Apple_Terminal" ]] {
    xterm_prompt=1
    prompt="[%U%l:%h%u] %~%#"
}

export CLICOLOR=1

if [[ ${+ORIGGID} -eq 0 ]]
then
    export ORIGGID="$GID"
fi

if [[ ${+LESS} -eq 0 ]]
then
    export LESS='-deiq'
    export LESSBINFMT='*u[%X]'
    export LESSCHARSET=latin1
fi

if [[ ${+PAGER} -eq 0 ]]
then
    if whence less >/dev/null 2>&1
    then
	export PAGER="`whence less`"
    fi
fi

export RSYNC_RSH=ssh

export UNDERZSH=$$

export QT_XFT=1

export LSCOLORS=dxcxcxdxaxegedabagacah