################################################################
#  PJE-0.1 ユーザ設定ファイルサンプル for zsh
#  Original made by MATSUMOTO Shoji (shom@i.h.kyoto-u.ac.jp)
#
#  zshell ユーザ設定ファイル for Plamo2.0
#  made by KATOU Takayuki
#  Time-stamp: <2000-08-15 04:02:45 rrr> , last edited.


# ログイン時以外 (ログインシェルでない場合) で、
# 対話シェルの場合に実行されます。

echo source .zshrc > /dev/stderr

# zsh option
setopt correct autolist autocd ignoreeof

##################################################
# stty (tty type の設定)
##################################################
stty erase ^H
stty intr ^C
stty susp ^Z
stty start undef
stty stop undef

#bindkey '^?' delete-char   # Del で文字を消す

##################################################
# color-ls
# 色設定等は ~/.dir_colors
##################################################
if which dircolors >& /dev/null; then
  eval `dircolors -z ~/.dir_colors`
else
  export LS_OPTIONS='-F -T 0 ';
  alias ls='/bin/ls $LS_OPTIONS';
fi
# export LS_OPTIONS="$LS_OPTIONS -N "
if [ "$TERM" = "dumb" ] ; then LS_OPTIONS="$LS_OPTIONS --color=no " ; fi

####################################################
#コマンドエイリアスの設定
####################################################
alias ll='ls -l'
alias la='ls -a'
alias lj='ls -N | nkf -e'
alias sl='ls'
alias startx='startx -- -bpp 16'
alias reboot='sudo -u root /sbin/reboot'
alias halt='sudo -u root /sbin/halt'
alias masl=xmasl
alias tail='tail -n 21'
alias head='head -n 21'
#alias 40tail='tail -n 40'
#alias jtail='tail -n 40  %1 | nkf -e'
#alias jhead='head %1 | nkf -e'
#alias jless='less %1 | nkf -e'
alias seyon='seyon -modem /dev/modem'
alias vt100='rxvt -bg black -fg white -sl 1000'
alias fetchnews='sudo -u news /usr/local/sbin/fetchnews'
# ghostview の代わりに gv を使う
alias ghostview='gv'
alias cls='clear'
#alias mule='mule -nw'
#alias w3m='w3m /web/rrr/index.html'
#alias seejpeg='seejpeg -c'


####################################################
# コマンドライン補完機能
####################################################

compctl -g '*(/) *.tex' jlatex
compctl -g '*(/) *.mp3 *.m3u *.MP3 *.M3U' mpg123
compctl -g '*(/) *.tex' platex
compctl -g '*(/) *.tex' latex 
compctl -g '*(/) *.dvi' dvi2ps
compctl -g '*(/) *.dvi' xdvi
compctl -g '*(/) *.gif *.GIF *.jpg *.JPG *.jpeg *.JPEG *.png *.PNG *.xpm *.xbm *.XPM *.XBM *.TIF *.tif *.TIFF *.tiff *.BMP *.bmp' ee
compctl -g '*(/) *.gif *.GIF *.jpg *.JPG *.jpeg *.JPEG *.png *.PNG *.xpm *.xbm *.XPM *.XBM *.TIF *.tif *.TIFF *.tiff *.BMP *.bmp' xv
compctl -g '*(/) *.gif *.GIF *.jpg *.JPG *.jpeg *.JPEG *.png *.PNG *.xpm *.xbm *.XPM *.XBM *.TIF *.tif *.TIFF *.tiff *.BMP *.bmp' display
compctl -g '*(/) *.ps *.eps *.epsi' gv
compctl -j kill
compctl -g '.*(/) *(/) *(@)' cd
compctl -g '* .*' less
#compctl -c man
compctl -c man jman jpman

# tar の補完
compctl -f -x \
        's[--]' -k "(atime-preserve remove-files checkpoint \
                force-local ignore-failed-read preserve same-owner \
                null totals exclude use-compress-program block-compress \
                unlink help)" -X 'available options are:' - \
        'C[-1,*z*] p[2]' -g "*.tar.(Z|z|gz) *.taz *.tgz (|.)*(-/)" - \
        'C[-1,*f*] p[2]' -g "*.tar (|.)*(-/)" + -g '*' - \
        'W[1,*x*][1,*t*] p[3, -1]' -K getfilenames  -- tar gtar
# get files' name in tar file
function getfilenames () {
    local a
    read -cA a
    if [ "$curfile" != "$a[3]" ] ; then
        if [ -f $a[3] ]; then
          if [ $a[3]:e = gz -o $a[3]:e = tgz -o $a[3]:e = Z ]; then
            reply=(`tar ztf $a[3]`)
          else
            reply=(`tar tf $a[3]`)
          fi
        else
          reply=()
        fi
        curfile=$a[3]
    fi
}


# ftp siteの補完
ftpsites=(ftp.iij.ad.jp upload.pluto.dti.ne.jp akegaras aotokage kawatonbo)
compctl -k ftpsites ftp

# urlの補完
urls=( \
     `grep \<A ~/.netscape/bookmarks.html |\
     sed -e 's/.*HREF\=\"//' -e 's/\".*//'`\
     )
html=('*.(html)')
compctl -k urls wget
compctl -k urls + -k html w3m

# xrdb (PJE の .Xdefaults では #ifdef XIM や #include を使っている)
alias xrdb='xrdb -DXIM=$XIM -I$HOME/.xres'

# prompt の設定
#PS1="%Bwarning! %n@%m%b:%2c%(#.#.$) "
#
PROMPT='%B%{[31m%}[%{[m%}%B%{[33m%}%n%{[m%}%B%{[32m%}@%m%{[m%}%B%{[31m%}]%{[m%}%B:%1c%(#.#.$) '
RPROMPT='%{[36m%}[%~]%{[m%}'

# kterm,xterm のタイトルに prompt を表示する
if [ "$TERM" = "screen" ] ; then
  SCREEN=screen@
fi
case $TERM in
kterm|xterm|screen)
    HN=$SCREEN`hostname -s`
    function termtitle () { echo "]0;$*" ; }
    function cd () { builtin cd $* ; termtitle $HN:$PWD ; }
    function popd () { builtin popd $* ; termtitle $HN:$PWD ; }
    function pushd () { builtin pushd $* ; termtitle $HN:$PWD ; }
    function pwd () { builtin pwd ; termtitle $HN:$PWD ; }
    function su () { termtitle $HN":su "$* ;
        if [ "$[1]" = "-c" ] ; then command su -c "$[2]";
        elif [ "$[2]" = "-c" ] ; then command su $[1] -c "$[3]" 
        elif [ "$[3]" = "-c" ] ; then command su - $[2] -c "$[4]"
        else command su $* ; fi
        termtitle $HN:$PWD ; }
    function rsh () {
	termtitle $HN":rsh "$*
	command rsh $* ; termtitle $HN:$PWD
    }
    function rlogin () {
	termtitle $HN":rlogin "$*
	command rlogin $*
	termtitle $HN:$PWD
    }
    function telnet () {
	termtitle $HN":telnet "$*
	command telnet $*
	termtitle $HN:$PWD
    }
    function screen () {
	command screen $*
	termtitle $HN:$PWD
    }
;;
esac

# key の設定 (Emacs)
bindkey -e
bindkey '\C-u' backward-kill-line
bindkey '\C-w' kill-region

HISTSIZE=100
SAVEHIST=100

# stty (tty type の設定)
#stty erase ^H
#stty intr ^C
#stty susp ^Z
#stty start undef
#stty stop undef

# fortune cookies

echo
fortune
echo

