###################################################################
#  Plamo Linux 桼ե륵ץ .zshrc
#                       Chisato Yamauchi (cyamauch@phyas.aichi-edu.ac.jp)
#                            Time-stamp: <2002-05-04 07:31:41 cyamauch>

#if [ $SHLVL = 1 ] ; then
#  PATH="$PATH:." ;
#fi

if [ "x.$TERM" = "x.linux" -o "x.$TERM" = "x.xterm" ] ; then
  LANG=C
else
  LANG=ja_JP.eucJP
fi
export LANG

LESS='-M -X'
EDITOR='emacs -nw'
PAGER='less'
export LESS EDITOR PAGER

HISTFILE=$HOME/.zhistory

# color-ls
#  ~/.dir_colors
if which dircolors >& /dev/null; then
  eval `dircolors -b ~/.dir_colors`
  LS_OPTIONS=(--color=auto -F -T 0 -N) ;
else
  LS_OPTIONS=(-F -T 0 -N) ;
fi

if [ "x.$TERM" = "x.dumb" ] ; then
    LS_OPTIONS=(-F -T 0 -N --color=none) ;
fi

export LS_OPTIONS
alias ls='/bin/ls $LS_OPTIONS';
alias dir='/bin/dir $LS_OPTIONS';
alias vdir='/bin/vdir $LS_OPTIONS';

# WindowΥȥС˥ȥǥ쥯ȥ
# ɽԲǽʾΥץץ
PS1='%n@%m[%~]%# '
# kterm,xterm,rxvt Υȥ prompt ɽ
case $TERM in
kterm|xterm|rxvt|dtterm|vt100)
    # WindowΥȥС˥ȥǥ쥯ȥ
    # ɽǽʾΥץץ
    #   ɽ㢪 hoge@host[/usr/X11R6/lib/X11/app-defaults]% _
    PS1='%n@%m[%~]%# '
    #   ɽ㢪 hoge@host[app-defaults]% _
    #PS1='%n@%m[%c]%# '
    HN="`hostname`:"
#    HN="`hostname -s`:"
    case "$TERM" in
    vt*)
	HN=""
    ;;
    esac
    function mkrmhmpwd () { BSBS_HOME=`echo "/$HOME"|/usr/bin/sed -e 's/\//\\\\\//g'` ;
	RMHMPWD=`echo "/$PWD"|/usr/bin/sed -e "s/$BSBS_HOME/~/g"` ;
	if [ "$RMHMPWD" = "/$PWD" ] ; then
	    RMHMPWD="$PWD"
	fi
    }
    # ٤ޥǤϤ
    # function mkrmhmpwd () { RMHMPWD="$PWD" ; }
    function termtitle () { echo -ne "\033]0;$TERM - $*\007" ; }
    function cd () { builtin cd $* ; mkrmhmpwd ; termtitle "$HN""[$RMHMPWD]" ; }
    function popd () { builtin popd $* ; mkrmhmpwd ; termtitle "$HN""[$RMHMPWD]" ; }
    function pushd () { builtin pushd $* ; mkrmhmpwd ; termtitle "$HN""[$RMHMPWD]" ; }
    #function pwd () { builtin pwd ; mkrmhmpwd ; termtitle "$HN""[$RMHMPWD]" ; }
    function su () { mkrmhmpwd ; termtitle "$HN""su $*($RMHMPWD)" ;
	command su $* ;
	mkrmhmpwd ; 
        termtitle "$HN""[$RMHMPWD]" ; }
    function rsh () {
	termtitle "$HN""rsh $*" 
	command rsh $* 
	mkrmhmpwd ; 
	termtitle "$HN""[$RMHMPWD]"
    }
    function rlogin () { 
	termtitle "$HN""rlogin $*" 
	command rlogin $* 
	mkrmhmpwd ; 
	termtitle "$HN""[$RMHMPWD]"
    }
    function telnet () { 
	termtitle "$HN""telnet $*" 
	command telnet $* 
	mkrmhmpwd ; 
	termtitle "$HN""[$RMHMPWD]"
    }
    function ssh () { 
	termtitle "$HN""ssh $*" 
	command ssh $* 
	mkrmhmpwd ; 
	termtitle "$HN""[$RMHMPWD]"
    }
#    mkrmhmpwd ; termtitle "$HN""[$RMHMPWD]"
;;
esac

typeset +x PS1
HISTSIZE=512
SAVEHIST=512
setopt autolist
setopt hist_ignore_all_dups
unsetopt prompt_cr
unsetopt hup
#setopt ignoreeof
bindkey "^[[5~" history-search-backward
bindkey "^[[6~" history-search-forward
bindkey "^[[A" history-search-backward
bindkey "^[[B" history-search-forward
#bindkey "^[[A" backward-word
#bindkey "^[[B" forward-word
bindkey "^[[3~" delete-char
bindkey "^[[1~" beginning-of-history
bindkey "^[[4~" end-of-history
bindkey "^[[7~" beginning-of-history
bindkey "^[[8~" end-of-history
stty erase '^?'
case "$TERM" in
kterm|xterm|sun)
    stty erase '^H'
    ;;
#vt*)
#    stty erase '^H'
#    ;;
esac
stty werase '^W'
stty stop undef

# aliases
alias h='history'
alias rmdvi='rm *.dvi ; rm *.log ; rm *.aux ; rm *.toc'
alias rmback='rm *~ ; rm *.bak'
alias j='jobs -l'
alias la='ls -a'
alias ll='ls -l'
alias z='suspend'
alias x='exit'
alias LS='ls -alF | command less -E'
alias mu='mule -rv'

# csh emulation
setenv () {
    if [ $# -eq 0 ]; then
	/usr/bin/printenv
    else
	export $1=$*[2,-1]
    fi
}
alias unsetenv=unset
