#
# .zshrc
#

#
# Path
#

export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin:~/bin:./:/home/sylvio/bin
export LANG=en_US.ISO8859-1
export LC_ALL=en_US.ISO8859-1
export MM_CHARSET=ISO-8859-1

#
# Allow one error for every three characters typed in approximate completer
#

zstyle -e ':completion:*:approximate:*' max-errors \
	'reply=( $(( ($#PREFIX+$#SUFFIX)/3 )) numeric )'
        
#
# Insert all expansions for expand completer
#

zstyle ':completion:*:expand:*' tag-order all-expansions

#
# Formatting and messages
#

zstyle ':completion:*' verbose yes
zstyle ':completion:*:descriptions' format '%B%d%b'
zstyle ':completion:*:messages' format '%d'
zstyle ':completion:*:warnings' format 'No matches for: %d'
zstyle ':completion:*:corrections' format '%B%d (errors: %e)%b'
zstyle ':completion:*' group-name ''

# Complete ..
zstyle ':completion:*' special-dirs true

# match uppercase from lowercase
zstyle ':completion:*' matcher-list 'm:{# a-z}={# A-Z}'

# offer indexes before parameters in subscripts
zstyle ':completion:*:*:-subscript-:*' tag-order indexes parameters

# 
# Command for process lists, the local web server details and host completion
#

# zstyle ':completion:*:processes' command 'ps -o pid,s,nice,stime,args'
# zstyle ':completion:*:urls' local 'www' '/var/www/htdocs' 'public_html'
zstyle '*' hosts $hosts

# Filename suffixes to ignore during completion (except after rm command)
zstyle ':completion:*:*:(^rm):*:*files' ignored-patterns '*?.o' '*?.c~' '*?.old' '*?.pro'
# the same for old style completion
#fignore=(.o .c~ .old .pro)

# ignore completion functions (until the _ignored completer
# zstyle ':completion:*:functions' *ignored-patterns* ' '
autoload -U compinit
compinit

# Execute functions in some magic arrays
typeset -ga preexec_functions
typeset -ga precmd_functions
typeset -ga chpwd_functions

HISTFILE=~/.histfile
HISTSIZE=5000
SAVEHIST=1000

export LISTMAX=1000
export EDITOR=vi
export NULLFS=1
export JAIL=/var/jail/data
export GPG_TTY=`tty`

#
# Vi Mode
#

bindkey -e
bindkey -M vicmd "j" history-search-forward
bindkey -M vicmd "k" history-search-backward
bindkey "^[[A" history-search-backward
bindkey "^[[B" history-search-forward
bindkey -M viins "^[[S" insert-last-word
bindkey -M viins "^[[18~" insert-last-word

#
# Aliasing
#

alias md5sum='gmd5sum'
alias more='less'
alias ftp='ncftp'
alias j='jobs -l'
alias ff='find ./ -iname $*'
alias l='ls -lFG'
alias ls='ls -FG'
alias l.='ls -dF .*' 
alias gvim="/usr/local/bin/gvim -geom 145x60 -font \"Terminus 7\""
alias ...='cd ../..'
alias sbp='ssh -l bpuser $*'
alias sgn='ssh -l gnuser $*'
alias x='startx >&! /tmp/x.out $*'
alias pastebinit='pastebinit -b http://freebsd.pastebin.com $*'
alias ssh-kr='ssh-keygen -R $*'
alias vless='vim -u /usr/local/share/vim/vim*/macros/less.vim'
alias cdp='cd /prs'
alias cdo='cd /home/orfaos'
alias vi='vim'

alias dcvs='env CVS_RSH=ssh cvs -d sylvio@dcvs.FreeBSD.org:/home/dcvs'
alias pcvs='env CVS_RSH=ssh cvs -d sylvio@pcvs.FreeBSD.org:/home/pcvs'
alias projcvs='env CVS_RSH=ssh cvs -d sylvio@projcvs.FreeBSD.org:/home/projcvs'
alias scvs='env CVS_RSH=ssh cvs -d sylvio@ncvs.FreeBSD.org:/home/ncvs'

if [ "$LOGNAME" = "root" ]; then
	alias mutt='/usr/bin/env LC_ALL=en_US.ISO8859-1 mutt -y'
else
	alias mutt='/usr/bin/env LC_ALL=en_US.ISO8859-1 mutt'
fi

#
# Shell functions
#

setenv() { typeset -x "${1}${1:+=}${(@)argv[2,$#]}" }  # csh compatibility
freload() { while (( $# )); do; unfunction $1; autoload -U $1; shift; done }

#
# Git Branches
#

git_prompt_info() {
	ref=$(/usr/local/bin/git symbolic-ref HEAD 2> /dev/null) || return
	echo "(${ref#refs/heads/})"
}

#
# Command Prompt
#

#PROMPT='%n@%B%m%b:%(#.%/#.%~>) '
#PROMPT='%n@%B%m%b$(git_prompt_info):%(#.%/#.%~>) '
PROMPT='%n@%B%m%b:%(#.%/#.%~>) '
RPROMPT='%B$(git_prompt_info)%b'

#
# Completion options
#

setopt   notify pushdtohome cdablevars autolist
setopt   autocd longlistjobs NO_BEEP braceccl
setopt   autoresume histignoredups pushdsilent noclobber
setopt   autopushd pushdminus extendedglob rcquotes mailwarning
setopt   printexitvalue prompt_subst
unsetopt bgnice autoparamslash listambiguous globdots recexact

#
# Changing XTerm Title
#

case $TERM in
	xterm*)
		precmd () { print -Pn "\e]0;%n@%m: %~\a"}
		;;
esac

#
# bsd games
#

[ -x /usr/games/fortune ] && \
	/usr/games/fortune -s && \
	echo ""
