#-----------------------------
# settings
#-----------------------------

# parameters
export SAVEHIST="1000"

# colors
autoload -U colors && colors

# zshoptions
unsetopt EXTENDED_HISTORY	# history: disable timestamp
  setopt HIST_IGNORE_DUPS	# history: no duplicates
  setopt HIST_IGNORE_ALL_DUPS	# history: no duplicates in entire history
  setopt HIST_REDUCE_BLANKS	# history: remove superfluous blanks
  setopt SHARE_HISTORY		# history: read and write on each command
  setopt PRINT_EIGHT_BIT	# print eight bit characters literally
unsetopt MAIL_WARNING		# mail: disable notification

#-----------------------------
# keybindings
#-----------------------------

# http://zshwiki.org/home/zle/bindkeys#why_isn_t_control-r_working_anymore
bindkey -e

bindkey -M emacs "$terminfo[kdch1]" delete-char
bindkey -M emacs "$terminfo[khome]" beginning-of-line
bindkey -M emacs "$terminfo[kend]" end-of-line

# move between words with alt+arrow
bindkey "[1;3C" forward-word
bindkey "[1;3D" backward-word

# fix "del" key: https://git.suckless.org/st/plain/FAQ
if [ $TERM = "st-256color" ]
then
	function zle-line-init () { echoti smkx }
	function zle-line-finish () { echoti rmkx }
	zle -N zle-line-init
	zle -N zle-line-finish
fi

#-----------------------------
# prompt
#-----------------------------

EXITCODE="%(?..%?%1v )"
if [ $EXITCODE = 0 ]
then
	unset COLORED_EXITCODE
else
	COLORED_EXITCODE="%{$fg_bold[red]%}${EXITCODE}"
fi

if [ $UID = 0 ]
then
	UID_COLOR="%{$fg_bold[red]%}"
else
	UID_COLOR="%{$fg_bold[cyan]%}"
fi

PROMPT="${COLORED_EXITCODE}${UID_COLOR}%n%{$reset_color%}@%m %B%~%b %{$fg_bold[green]%}%#%{$reset_color%} "

#-----------------------------
# window title
#-----------------------------

case $TERM in
xterm*|rxvt*)
	precmd () { print -Pn "\e]0;%n@%M %~ - $TERM\a" }
	preexec () { print -Pn "\e]0;%n@%M %~ %# $1 - $TERM\a" }
	;;
screen*)
	precmd () { print -Pn "\e]0;%n@%M %~ \a" }
	preexec () { print -Pn "\e]0;%n@%M %~ %# $1\a" }
	;;
esac

#-----------------------------
# global shell settings
#-----------------------------

source ~alex/.shrc

ZLS_COLORS=$ZLS_COLORS
