.zshrcの設定メモ


このエントリーをはてなブックマークに追加

自分用に.zshrcを整理したついでに公開します。適宜更新。

# .zshrc

PATH=$HOME/usr/bin:/share/usr/bin:/usr/local/bin:/usr/X11R6/bin:/sbin:/bin:/usr/sbin:/usr/bin
HISTSIZE=100000
SAVEHIST=100000
HISTFILE=$HOME/.zsh_history
WORDCHARS='*?_-.[]~&;!#$%^(){}<>'

export LANG=ja_JP.eucJP
export EDITOR=emacsclient
export LS_COLORS=':no=00:fi=00:di=36:ln=35:pi=33:so=32:bd=34;46:cd=34;43:ex=31:'
export PERL5LIB=$HOME/usr/lib/perl

#grepでマッチした部分に色をつける
export GREP_COLOR="01;34"
export GREP_OPTIONS=--color=auto

# options
setopt auto_cd
setopt auto_param_slash
setopt auto_pushd
setopt auto_remove_slash
setopt complete_in_word
setopt extended_glob
setopt extended_history
setopt function_argzero
setopt hist_ignore_dups
setopt hist_reduce_blanks
setopt ignore_eof
setopt list_types
setopt noflowcontrol      #フロー制御(C-s, C-q)を無効に
setopt nohup
setopt no_nomatch
setopt print_eight_bit
setopt pushd_ignore_dups
setopt pushd_silent
setopt pushd_to_home
setopt sun_keyboard_hack
setopt share_history
unsetopt promptcr

# aliases
alias la='ls -a' 
alias ll='ls -lh'
alias ls='ls -F --color=tty'
alias lla='ls -alh'
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
alias dir='vdir -h --color'
alias pw='perl -w'
alias h='history'
alias e='emacs'
alias p='perl'
alias cpan='perl -MCPAN -e shell'
alias -g L='| lv'
alias -g H='| head'
alias -g T='| tail'
alias -g W='| wc'
alias -g G='| grep'

# completion
autoload -U compinit
compinit

zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}

# bindkey
bindkey "^[f" emacs-forward-word
bindkey "^[b" emacs-backward-word

autoload history-search-end
zle -N history-beginning-search-backward-end history-search-end
zle -N history-beginning-search-forward-end history-search-end
bindkey "^[p" history-beginning-search-backward-end
bindkey "^[n" history-beginning-search-forward-end

autoload replace-string
zle -N replace-string
bindkey "^[%" replace-string

if [ "$EMACS" = t ]; then
    unsetopt zle
    stty -echo
    alias ls='ls -F --color'
fi

# プロンプトに色を付ける                                                                                                                                    
# この書き方だと、^[ (エスケープ。Ctrl-q ESC で入力)を使わずに済むっぽい                                                                                                  
local GREEN=$'%{\e[1;32m%}'
local BLUE=$'%{\e[1;34m%}'
local DEFAULT=$'%{\e[m%}'
PROMPT=$GREEN'[%m-(%~)] %(!.#.$) '$DEFAULT
setopt PROMPT_SUBST

#cd後自動でls
#function cd() { builtin cd $@ && ls; }

#ゴミ箱 http://www.q-eng.imat.eng.osaka-cu.ac.jp/~ippei/unix/shell.html#l6 より
#rm -i のオプションと衝突してしまう
function rm() {

    if [ -d ~/.trash ]; then
        local DATE=`date "+%y%m%d-%H%M%S"`
        mkdir ~/.trash/$DATE
        for i in $@; do
            if [ -e $i ]; then
                mv $i ~/.trash/$DATE/
		echo "move $i to ~/.trash/$DATE/ :";
            else 
                echo "$i : not found"
            fi
        done
    else
        #/bin/rm -i $@
	echo "please mkdir ~/.trash"
    fi
}