##key settings
bindkey -e
bindkey '^p' history-beginning-search-backward
bindkey '^n' history-beginning-search-forward

function chpwd() { ls -aF }

function cd () {
    if [ $# = 0 ]; then
        builtin cd
    elif [ -f $1 ]; then
        builtin cd $1:h
    else
        builtin cd $*
    fi
}

#function setenv    () { 
#    if [ $# -eq 0 ]; then env; else export ${1}=$*[2,-1]; export ${1}; fi }
#function unsetenv  () { unset $* }

##sets of setopt
setopt prompt_subst
setopt auto_cd
setopt no_beep
setopt no_list_beep
setopt auto_list
#unsetopt bash_auto_list
unsetopt list_ambiguous
unsetopt menu_complete
setopt auto_menu
setopt always_last_prompt
setopt complete_in_word
#setopt always_to_end
setopt list_types
#setopt recexact
setopt auto_remove_slash
setopt auto_param_keys
setopt extended_glob
setopt correct
setopt multios

##sets of alutoload
autoload predict-on
predict-on

autoload -U compinit
compinit

##sets of zstyle
zstyle ':completion:*' verbose yes
#zstyle ':completion:*' completer _expand _complete _match _prefix _approximate _list _history
zstyle ':completion:*:messages' format $YELLOW'%d'$DEFAULT
zstyle ':completion:*:warnings' format $RED'No matches for:'$YELLOW' %d'$DEFAULT
zstyle ':completion:*:descriptions' format $YELLOW'completing %B%d%b'$DEFAULT
zstyle ':completion:*:corrections' format $YELLOW'%B%d '$RED'(errors: %e)%b'$DEFAULT
zstyle ':completion:*:options' description 'yes'
zstyle ':completion:*' format '%BCompleting %d%b'
zstyle ':completion:*' group-name ''
zstyle ':completion:*:default' menu select=1
zstyle ':predict' verbose true #notice if predict-on is enabled/disabled. use C-xp to enable, C-xC-p to disable.


##settings of terminal
case $TERM in
    emacs|unknown|dumb)
	PROMPT='%n:%l@%m:%~[%h]%T$ '
    ;;
    sun|eterm)
	PROMPT='%n:%l@%m$ '
	RPROMPT='%~[%h]%T'
    ;;
    screen|vt100) # screen$BMQ(B
	PROMPT='%{[$[35]m%}%n%{[m%};%{[$[36]m%}%l%{[m%}@%{[$[33]m%}%m%{[m%}$ '
	RPROMPT='%{[$[34]m%}%~%{[m%}[%{[$[32]m%}%h%{[m%}]%{[$[37]m%}%W, %*%{[m%}'
    ;;
    kterm|xterm)
	PROMPT=$'%{[$[35]m%}%n%{[m%}:%{[$[36]m%}%l%{[m%}@%{[$[33]m%}%m%{[m%}, %{[$[34]m%}%~%{[m%} \n ('$(uptime | sed -e "s/ average:/,/g" | awk -F, '{ print $4 }')'%% ) $ '
	PROMPT2='%_%%'
	RPROMPT='[%{[$[32]m%}%h%{[m%}]%{[$[37]m%}%W, %*%{[m%}'
	RPROMPT2='%{[$[37]m%}%W, %*%{[m%}'
    ;;
    *)
	PROMPT='%n;%l@%m;%~[%h]%T$ '
    ;;
esac
[[ $EMACS = t ]] && unsetopt zle


##settings of history
setopt hist_ignore_dups
setopt hist_ignore_space
setopt ignore_eof
export HISTFILE=$HOME/.zsh_history
export HISTSIZE=100000
export SAVEHIST=100000
setopt extended_history
setopt share_history
setopt autopushd

##settings of aliases
alias ls='ls -hai'
alias ztetrispre='autoload -U tetris; zle -N tetris;echo "type M-x tetris"'

##settings for extenstion like Windows
alias -s {html,htm}=firefox
alias -s {txt,css}=gedit
alias -s dvi=xdvi
alias -s php=php
alias -s pdf=acroread
alias -s {odt,ott,sxw,sdw,stw,vor,ods,odp,doc,dot,xls,ppt,rtf,pdb,psw,wpd,jtd,jtt,hwp,wps,sxc}=soffice
alias -s {tgz,lzh,zip,arc,tar,war,zoo,bz2,bz,arj,ear,jar}=file-roller
#alias -s rar=unrar

##replacement word with another strings
alias -g '...'='../../'

##load module for zsh
zmodload zsh/zftp
