#
# /etc/zshrc is sourced in interactive shells.  It
# should contain commands to set up aliases, functions,
# options, key bindings, etc.
#

## shell functions
#setenv() { export $1=$2 }  # csh compatibility

# Set prompts
#PROMPT='[%n@%m]%~%# '    # default prompt
autoload -U colors && colors

if [[ "`whoami`" == "root" ]]
then
        PROMPT="%{$fg[red]%}%B%n%b%{$reset_color%}@%{$fg[blue]%}%B%m%b%{$reset_color%}:%{$fg[yellow]%}%~%{$reset_color%}# "
else
        PROMPT="%{$fg[green]%}%B%n%b%{$reset_color%}@%{$fg[blue]%}%B%m%b%{$reset_color%}:%{$fg[yellow]%}%~%{$reset_color%}$ "

        SUDO="`which sudo 2> /dev/null`"
        if [ -z "${SUDO}" ]
        then
                SUDO="su -c"
        fi
fi
#RPROMPT=' %~'     # prompt for right side of screen

# bindkey -v             # vi key bindings
# bindkey -e             # emacs key bindings
bindkey ' ' magic-space  # also do history expansion on space

# Provide pathmunge for /etc/profile.d scripts
pathmunge()
{
    if ! echo $PATH | /bin/grep -qE "(^|:)$1($|:)" ; then
        if [ "$2" = "after" ] ; then
            PATH=$PATH:$1
        else
            PATH=$1:$PATH
        fi
    fi
}

_src_etc_profile_d()
{
    #  Make the *.sh things happier, and have possible ~/.zshenv options like
    # NOMATCH ignored.
    emulate -L ksh


    # from bashrc, with zsh fixes
    if [[ ! -o login ]]; then # We're not a login shell
        for i in /etc/profile.d/*.sh; do
	    if [ -r "$i" ]; then
	        . $i
	    fi
        done
        unset i
    fi
}
_src_etc_profile_d

unset -f pathmunge _src_etc_profile_d

PATH="${PATH}:/scripts"
HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000
setopt appendhistory autocd
unsetopt beep
autoload -Uz compinit && compinit

alias S="$SUDO zsh"

if which systemctl >/dev/null 2>&1
then
        alias sctl="${SUDO} systemctl"
fi

# KeyBindings
keys_set_xterm() {
	bindkey "^[[1~" beginning-of-line
	bindkey "^[[3~" delete-char
	bindkey "^[[4~" end-of-line
	
	bindkey "^[[H" beginning-of-line
	bindkey "^[[F" end-of-line

#	bindkey "${terminfo[khome]}" beginning-of-line
#	bindkey "${terminfo[kend]}"  end-of-line
#	bindkey "${terminfo[kdch1]}"  delete-char
}
case $TERM in
	"screen.linux")
		keys_set_xterm
		;;
	"xterm")
		keys_set_xterm
		;;
	"xterm-256color")
		keys_set_xterm
		;;
	*)
		echo "Unknown Terminal"
		keys_set_xterm
		;;
esac

if [ -f "${HOME}/.aliases" ]
then
	. "${HOME}/.aliases"
fi

