# ZShell Configuration

#echo "Initializing ZShell..."
REESEZSHRC="true"

# Environment
if [ -z "$REESEPROFILE" ]; then
	. ${HOME}/.profile
fi

PS1="%n@%m[%~] "
RPS1="< %T"

FPATH="${FPATH}:${HOME}/.zsh/functions"
SHELL=`which zsh`

# Aliases
if [ -f ${HOME}/.alias ]; then
	. ${HOME}/.alias
fi

# Options

HISTFILE=${HOME}/.zhist
HISTSIZE=1000
SAVEHIST=1000

setopt alwaystoend
setopt autocd
setopt automenu
setopt append_history
setopt completeinword
setopt correct
setopt correctall
setopt dvorak
setopt extended_glob
setopt hist_ignore_dups
setopt histverify
setopt ignore_eof
setopt nocheckjobs
setopt nohup
setopt print_exit_value

unsetopt beep
unsetopt notify

bindkey -e

# Modules
autoload colors
autoload -Uz compinit
compinit

# Custom Completion
compctl -k "( push pull up down )" workspace

#
# ZShell Functions
#

# chpwd - called autmagically with `cd`
#chpwd () { print -Pn "\033]0;%n@%m[%~]\007" }

# format titles for screen and rxvt
function title() {
  # escape '%' chars in $1, make nonprintables visible
  a=${(V)1//\%/\%\%}

  case $TERM in
  screen*)
    a=$(print -Pn "%20>...>$a" | tr -d "\n")
    print -Pn "\ek$a:$3\e\\"      # screen title (in ^A")
    ;;
  xterm*|rxvt)
    a=$(print -Pn "%40>...>$a" | tr -d "\n")
    print -Pn "\e]2;$2 | $a:$3\a" # plain xterm title
    ;;
  esac
}

# precmd is called just before the prompt is printed
function precmd() {
  title "zsh" "$USER@%m" "%55<...<%~"
}

# preexec is called just before any command line is executed
function preexec() {
  title "$1" "$USER@%m" "%35<...<%~"
}


# namedir <dir> - add a short ~<dir> path alias
namedir () { $1=$PWD ;  : ~$1 }

# Custom commands
mkcd () { mkdir -p $1; builtin cd $1 }
mkpu () { mkdir -p $1; pu $1 }
recd () { PWDTMP=$PWD && cd .. && mv $PWDTMP $1 && cd $1 }

# Debian package holding
hold() {
    for i in $*; do
    echo "$i hold"
    done | sudo dpkg --set-selections
}

unhold() {
    for i in $*; do
    echo "$i install"
    done | sudo dpkg --set-selections
}

lshold() {
    dpkg -l | grep '^h'
}


#
# Keybindings for Gnome-Terminal
#

# Up/Down Search
bindkey '\e[A' up-line-or-search
bindkey '\e[B' down-line-or-search

# Delete
bindkey '[3~' delete-char

# Home/End
bindkey 'OH' beginning-of-line
bindkey 'OF' end-of-line

# Ctrl Left/Right (^[[1;5D & ^[[1;5C)
bindkey '[1;5D' backward-word
bindkey '[1;5C' forward-word

#
# System Specific zshrc
#
if [ -f ${HOME}/.zsh_local ]; then
    . ${HOME}/.zsh_local
fi

