#
# Zsh configuration file
# Since 2006,  kolter <kolter@openics.org>
#
#  This file is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY
#

# define personal zsh config directory
export ZSHDOTDIR="${HOME}/.zsh"

# redefine PATH
export PATH="${HOME}/bin:${HOME}/.bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"

# load prezto
BUNDLES_ROOT="${ZSHDOTDIR}/bundles"
PREZTO_INIT="${BUNDLES_ROOT}/prezto/init.zsh"
OVERRIDES_ROOT="${ZSHDOTDIR}/overrides"
OVERRIDES_PREZTO_INIT="${OVERRIDES_ROOT}/prezto/init.zsh"
if [ -f "${PREZTO_INIT}" ]; then
    export ZDOTDIR="${BUNDLES_ROOT}"
    source "${PREZTO_INIT}"
    export ZDOTDIR="${OVERRIDES_ROOT}"
    source "${OVERRIDES_PREZTO_INIT}"
    unset ZDOTDIR
fi
unset BUNDLES_ROOT PREZTO_INIT OVERRIDES_ROOT OVERRIDES_PREZTO_INIT

# overide insecure stuff with compinit while using 'sudo zsh'
# my functions (don't forget to modify fpath before call compinit !!)
#if [ -z "$SUDO_USER" -a "$UID" != 0 ]; then
#    fpath=($ZSHDOTDIR/functions.d $fpath)
#fi

# include custom configuration
for f in ${ZSHDOTDIR}/config/*.zsh; do
    if [[ -r "${f}" ]]; then
        . "${f}"
    fi
done

# using 'sudo zsh'
if [ "$SUDO_USER" -a "$UID" = 0 ]; then
    # define root history path
    export HISTFILE="$ZSHDOTDIR/history/history_root"
    # ugly hack : reset some file perms to normal to avoid warnings
    chmod 0644 ~/.zcompdump
    chown "$SUDO_USER:$SUDO_USER" ~/.zcompdump
fi
