#
# 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 DOTZSHDIR="$HOME/.zsh.d"

# redefine PATH
export PATH=$HOME/bin:$DOTZSHDIR/bin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/X11R6/bin:/usr/games

# 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=($DOTZSHDIR/functions.d $fpath)
fi

autoload -U zutil
autoload -U compinit
autoload -U complist
compinit

# include custom functions
for f in $DOTZSHDIR/lib.d/*.zsh; do
    [ -r "$f" ] && source $f
done

# per OS resource file
os=$(uname)
# special case
if [ "$os" = "GNU/kFreeBSD" ]; then
    os="Linux"
fi
if [ -r "$DOTZSHDIR/os.d/${os}.zsh" ]; then
    source "$DOTZSHDIR/os.d/${os}.zsh"
fi
unset os

# sourcing config files
for f in $DOTZSHDIR/config.d/*.zsh; do
    if [ -r "$f" ]; then
        source $f
    fi
done

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

# sourcing extra file
if [ -r "$DOTZSHDIR/extra.zsh" ]; then
    source "$DOTZSHDIR/extra.zsh"
fi

