#
# 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
#

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

# define personal zsh config directory
export DOTZSHDIR="$HOME/.zsh.d"

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

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
local os=$(uname)
[ -r "$DOTZSHDIR/os.d/${os}.zsh" ] && source "$DOTZSHDIR/os.d/${os}.zsh"

# sourcing config files
for f in $DOTZSHDIR/config.d/*.zsh; do
    [ -r "$f" ] && source $f
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
[ -r "$DOTZSHDIR/extra.zsh" ] && source "$DOTZSHDIR/extra.zsh"