zshrc

いろいろいじったので忘れないように残しておく。

# bindkey -v             # vi key bindings
bindkey -e             # emacs key bindings
# bindkey ' ' magic-space  # also do history expansion on space

## shell functions
#setenv() { export $1=$2 }  # csh compatibility

####################################################################
# local variable
#
local GRAY=$'%{\e[1;30m%}'
local LIGHT_GRAY=$'%{\e[0;37m%}'
local WHITE=$'%{\e[1;37m%}'

local LIGHT_BLUE=$'%{\e[1;36m%}'
local YELLOW=$'%{\e[1;33m%}'
local PURPLE=$'%{\e[1;35m%}'
local GREEN=$'%{\e[1;32m%}'
local BLUE=$'%{\e[1;34m%}'
local DEFAULT=$'%{\e[1;00m%}'

####################################################################
# prompt settings
#

# Set prompts
#PROMPT='[%n@%m]%~%# '    # default prompt
#RPROMPT=' %~'     # prompt for right side of screen

PROMPT=$LIGHT_BLUE'[${USER}@${HOST}] %(!.#.$) '$DEFAULT
RPROMPT=$LIGHT_BLUE'[%~]'$DEFAULT
setopt PROMPT_SUBST

if [ "$TERM" = "screen" ]; then
  PROMPT=$LIGHT_BLUE'[${USER}@${HOST} win:[$WINDOW]] %(!.#.$) '$DEFAULT
  chpwd () { echo -n "^[_`dirs`^[\\" }
  preexec() {
    # see [zsh-workers:13180]
    # http://www.zsh.org/mla/workers/2000/msg03993.html
    emulate -L zsh
    local -a cmd; cmd=(${(z)2})
    case $cmd[1] in
      fg)
        if (( $#cmd == 1 )); then
          cmd=(builtin jobs -l %+)
        else
          cmd=(builtin jobs -l $cmd[2])
        fi
        ;;
      %*)
        cmd=(builtin jobs -l $cmd[1])
        ;;
      cd)
        if (( $#cmd == 2)); then
          cmd[1]=$cmd[2]
        fi
        ;&
      *)
        echo -n "^[k$cmd[1]:t^[\\"
        return
        ;;
    esac

    local -A jt; jt=(${(kv)jobtexts})

    $cmd >>(read num rest
      cmd=(${(z)${(e):-\$jt$num}})
      echo -n "^[k$cmd[1]:t^[\\") 2>/dev/null
  }
  chpwd
fi

precmd() {
    hostnam=${HOST##.*}     # wildcard, not regex!
    usernam=$(whoami)
    newPWD=${PWD}
    promptstr="--(${usernam}@${hostnam})-<mm/dd-hh:mm>---(${PWD})--"
    fillsize=$(( ${COLUMNS} - ${#promptstr} ))
    if [ $fillsize -ge 0 ]
    then
        fill=${(l.${fillsize}..-.)}
    else
        fill=""
        offset=$(( (${fillsize}*(-1)) + 4 ))
        newPWD="..."${newPWD[${offset},-1]}
    fi
}

termwide() {
    PROMPT=$YELLOW"-"$BLUE"-("$YELLOW"\${usernam}"$LIGHT_BLUE"@"$YELLOW"\${hostnam}"\
    $BLUE")-<"$YELLOW"%D{%m}"$LIGHT_BLUE"/$YELLOW%D{%d}"$BLUE"-"\
    $PURPLE"%D{%H}"$LIGHT_BLUE":"$PURPLE"%D{%M}"$BLUE">-"\
    $YELLOW"-\${fill}"$BLUE"-("$YELLOW"\${newPWD}"$BLUE")-"$YELLOW"-"\
    $'\n'\
    $YELLOW"-"$BLUE"-["\
    $YELLOW"%h"\
    $BLUE"]"$WHITE"%#"\
    $'%{\e[0m%} '

    PROMPT2=$LIGHT_BLUE"-"$YELLOW"-"$YELLOW"-"$LIGHT_GRAY$'%{\e[0m%} '
}

####################################################################
# enable prompt color
autoload -U colors
colors

####################################################################
# enable contents assist at default
autoload -U compinit
compinit

####################################################################
# Set shell options
###
setopt auto_menu auto_cd correct auto_name_dirs auto_remove_slash
setopt pushd_ignore_dups rm_star_silent sun_keyboard_hack
setopt extended_glob list_types no_beep always_last_prompt
setopt cdable_vars sh_word_split auto_param_keys

####################################################################
# history settings
#
setopt hist_ignore_all_dups
setopt hist_ignore_space
setopt share_history
setopt inc_append_history

setopt extended_history

HISTFILE=/var/zsh-history
HISTSIZE=100000
SAVEHIST=1000000
function history-all { history -E 1 }

####################################################################
# alias settings
#
alias ls='ls -G'
alias -g L="| $PAGER"
alias -g M="| $PAGER"
alias -g G='| grep'
alias -g C='| cat -n'
alias -g W='| wc'
alias -g H='| head'
alias -g T='| tail'
alias -g ....='../..'