[from now] 2012/05/29 03:51:17

diff --git c/.gitignore i/.gitignore
index d787ecb..ea193ee 100644
--- c/.gitignore
+++ i/.gitignore
@@ -6,6 +6,9 @@
 !zsh
 zsh/*
 !zsh/README.md
+!zsh/zshrc
+!zsh/zshenv
+
 !zsh/bin/
 !zsh/bundle/
 !zsh/functions/
diff --git c/zsh/zshenv i/zsh/zshenv
new file mode 100644
index 0000000..325b63b
--- /dev/null
+++ i/zsh/zshenv
@@ -0,0 +1 @@
+export LANG=en_US.UTF-8
diff --git c/zsh/zshrc i/zsh/zshrc
new file mode 100644
index 0000000..c862ce8
--- /dev/null
+++ i/zsh/zshrc
@@ -0,0 +1,973 @@
+# -*- coding: utf-8-unix; -*-
+##
+# .Zshrc
+# $lowercase = (array)
+# e.g., path=()
+# $UPPERCASE = {string}
+# e.g., PATH=""
+##
+# ZSHRC_VERBOSE
+# =0 : no verbosity (only errors)
+# >0 : print files loaded & warns when (re)compiled
+# >1 : print functions zrcautoload cannot find
+# >2 : print functions zrcautoload loads
+# >3 : make version checking verbose
+#ZSHRC_VERVOSE=${ZSHRC_VERBOSE:-0}
+##
+# ZSHRC_COMPILE:
+# =0 : don't
+# >0 : use zcompile
+#ZSHRC_COMPILE=1
+##
+#function zprintf() {
+#    local -i level; local format
+#    level=$1; format=$2; shift; shift
+#    (( ZSHRC_VERBOSE < level )) && return 0
+#    printf '[%2s] '${format} ${level} "$@"
+#    return $?
+#}
+##
+typeset -ga zle_init_functions
+typeset -ga zle_finish_functions
+typeset -ga zle_keymap_functions
+##
+#setopt NO_all_export
+#setopt NO_global_export
+#setopt correct
+#setopt NO_correct_all
+#setopt NO_flow_control
+
+#setopt hash_cmds
+#setopt hash_dirs
+
+#setopt igonore_eof
+
+#setopt NO_interactive_comments
+#setopt NO_path_dirs
+#setopt NO_print_exit_value
+#setopt NO_mail_warn
+
+#setopt aliases
+##
+#setopt bad_pattern
+#setopt equals
+#setopt extended_glob
+#setopt glob
+
+#setopt NO_glob_dots # don't req. leadint dot for hidden files
+
+#setopt multibyte
+
+
+function exists {
+  which $1 &> /dev/null
+}
+
+set_flags() {
+    if [[ $(uname) = "Darwin" ]]; then
+        IS_OSX=true
+        if [[ -x `which brew` ]]; then
+            HAS_BREW=true
+        else
+            HAS_BREW=false
+        fi
+    else
+        IS_OSX=false;
+    fi
+
+    if [[ $(uname) = "Linux" ]]; then
+        IS_LINUX=true;
+        if [[ -x `which apt-get` ]]
+            then HAS_APT=true
+            else HAS_APT=false
+        fi
+        if [[ -x `which yum` ]]
+            then HAS_YUM=true
+            else HAS_YUM=false
+        fi
+    else
+        IS_LINUX=false;
+    fi
+}; set_flags;
+
+set_env_vars() {
+    umask 022
+    limit coredumpsize 0
+    _zsh_user_config_dir="${HOME}/.zsh"
+    if [[ ! -d ${_zsh_user_config_dir} ]]; then
+        mkdir -p ${_zsh_user_config_dir}
+    fi
+    autoload -Uz add-zsh-hook
+
+    export LANG="en_US.UTF-8"
+    export LC_ALL="en_US.UTF-8"
+    export D0TDIR=$HOME/etc/d0tfiles
+    export CLICOLOR=1
+    export BLOCK_SIZE="human-readable"
+
+    export WORDCHARS=${WORDCHARS:s,/,,}
+
+
+    #ls color
+    if which dircolors >/dev/null 2>&1 ;then
+        # export LS_COLORS
+        eval $(dircolors -b)
+        #not use bold
+        if which perl >/dev/null 2>&1 ;then
+            LS_COLORS=$(echo $LS_COLORS | LANG=C perl -pe 's/(?<= [=;] ) 01 (?= [;:] )/00/xg')
+        fi
+    else
+        # dircolors is not found
+        export LS_COLORS="di=00;34:ln=00;36:so=00;35:ex=00;32:bd=40;33;00:cd=40;33;00:su=37;41:sg=30;43:tw=30;42:ow=34;42"
+    fi
+    zstyle ':completion:*' list-colors ${(s.:.)LS_COLORS}
+
+    set_man_colors() {
+    # Less Colors for Man Pages
+    # http://linuxtidbits.wordpress.com/2009/03/23/less-colors-for-man-pages/
+        export LESS_TERMCAP_mb=$'\E[01;31m'       # begin blinking
+        export LESS_TERMCAP_md=$'\E[01;38;5;74m'  # begin bold
+        export LESS_TERMCAP_me=$'\E[0m'           # end mode
+        export LESS_TERMCAP_se=$'\E[0m'           # end standout-mode
+        export LESS_TERMCAP_so=$'\E[38;33;246m'   # begin standout-mode - info box
+        export LESS_TERMCAP_ue=$'\E[0m'           # end underline
+        export LESS_TERMCAP_us=$'\E[04;38;5;146m' # begin underline
+    }
+    set_man_colors;
+
+    setup_grep() {
+        export GREP_OPTIONS="--color=auto"
+        export GREP_COLOR="1;32"
+    }
+    setup_grep;
+
+    set_path() {
+        export PATH=/usr/local/bin:/usr/local/sbin:$PATH
+        typeset -gxU PATH=$PATH # remove dup path
+    }
+    set_path;
+}; set_env_vars;
+
+setup_perl() {
+    export PERLBREW_ROOT=/usr/local/lib/perlbrew
+    if [[ -e /usr/local/lib/perlbrew/etc/bashrc ]]; then
+        source /usr/local/lib/perlbrew/etc/bashrc
+        alias plbrew='perlbrew'
+    fi
+}; setup_perl;
+function setup_python() {
+    export PYTHONDONTWRITEBYTECODE=true
+    export VIRTUALENV_DISTRIBUTE=true
+    export PYTHONPATH=/usr/local/lib/python:$PYTHONPATH
+    export PATH=/usr/local/share/python:$PATH
+}; setup_python
+
+setup_ruby() {
+    # Ruby
+    alias gemi='gem install --no-ri --no-rdoc'
+    if [[ -d $HOME/.rvm ]] && [[ -d $HOME/.rbenv ]]; then
+        echo ''
+        echo 'ERROR!'
+        echo 'Found both `~/.rvm` and `~/.rbenv`'
+        echo 'You channot use both of these simulatenously.'
+        echo 'Delete one and reload zsh'
+        echo ''
+    else
+        if [[ -d $HOME/.rvm ]]; then
+            [[ -s "$HOMe/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
+        fi
+        if [[ -d $HOME/.rbenv ]]; then
+            eval "$(rbenv init -)"
+        fi
+    fi
+}; setup_ruby;
+# RUBY=`which ruby`
+
+setup_nodejs() {
+    export NODE_PATH=/usr/local/lib/node_modules
+}; setup_nodejs
+
+setup_clojure() {
+    export CLOJURESCRIPT_HOME=$HOME/.cljs
+    export PATH=$PATH:$CLOJURESCRIPT_HOME/bin
+    function cljsca() { cljsc $1.cljs '{:optimizations :advanced}' > $1.js }
+
+    clojure_helpers() {
+    }
+    # clojure_helpers;
+
+}; setup_clojure
+setup_haxe() {
+    export HAXE_LIBRARY_PATH="$(brew --prefix)/share/haxe/std"
+}; # setup_haxe
+
+
+__zsh() {
+    setup_zmv() {
+        autoload -U zmv
+        alias zmv='noglob zmv -W'
+    }
+    setup_zmv;
+
+    setup_history() {
+        # HISTORY
+        HISTFILE=$HOME/.zsh/history
+        HISTSIZE=10000000
+        SAVEHIST=$HISTSIZE
+        setopt hist_reduce_blanks
+        setopt share_history
+        setopt append_history
+        setopt hist_verify
+        setopt inc_append_history
+        setopt extended_history
+        setopt hist_expire_dups_first
+
+        setopt hist_ignore_space
+        setopt hist_ignore_dups
+
+        setopt hist_expand
+        # do not add unnecessary command line to history
+        _history_ignore() {
+            local line=${1%%$'\n'}
+            local cmd=${line%% *}
+            [[ ${#line} -ge 5 &&
+               ${cmd} != "rm" &&
+               ${cmd} != (l|l[sal]) &&
+               ${cmd} != (c|cd) &&
+               ${cmd} != (m|man) ]]
+        }
+        add-zsh-hook zshaddhistory _history_ignore
+        setopt no_flow_control
+    }
+    setup_history;
+
+    set_opt() {
+        setopt numeric_glob_sort
+        setopt extended_glob
+
+        setopt magic_equal_subst
+
+        setopt auto_pushd
+        setopt pushd_to_home
+        setopt pushd_minus
+        setopt pushd_silent
+        setopt NO_auto_cd
+        setopt glob_dots
+        setopt correct
+        setopt rc_quotes
+        setopt long_list_jobs
+        setopt auto_resume
+        setopt extended_glob
+        setopt auto_list
+        setopt auto_param_slash
+        setopt list_packed
+        setopt rec_exact
+        setopt auto_name_dirs
+        setopt pushd_ignore_dups
+        setopt no_beep
+        setopt multios
+        setopt cdablevarS
+
+        setopt prompt_subst
+        setopt transient_rprompt
+
+        setopt ignore_eof
+
+        setopt print_eight_bit
+    }
+    set_opt;
+
+    unset_opt() {
+        unsetopt bg_nice
+        unsetopt hup
+        unsetopt prompt_cr
+        unsetopt beep
+        unsetopt list_beep
+    }
+    unset_opt;
+
+    setup_zle() {
+        ## ZLE
+        set -o vi
+        bindkey -v
+        # bindkey -e
+        bindkey '^A' beginning-of-line
+        bindkey '^E' end-of-line
+        bindkey '^F' forward-char
+        bindkey '^B' backward-char
+
+        bindkey -M main "^[" vi-cmd-mode
+        bindkey -M vicmd "/" history-incremental-search-backward
+        bindkey -M vicmd "q" push-line
+        bindkey -M vicmd "v" set-mark-command
+        bindkey -M vicmd "y" copy-region-as-kill
+
+        bindkey -M viins '^A' vi-beginning-of-line
+        bindkey -M viins '^E' vi-end-of-line
+
+        autoload -U 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
+
+        zmodload -i zsh/parameter
+        insert-last-command-output() {
+            LBUFFER+="$(eval $history[$((HISTCMD-1))])"
+        }
+        zle -N insert-last-command-output
+        bindkey "^X^L" insert-last-command-output
+
+        autoload -U url-quote-magic
+        zle -N self-insert url-quote-magic
+    }
+    setup_zle;
+
+    setup_zsh_hooks() {
+        # functions as array
+        typeset -ga chpwd_functions
+        typeset -ga precmd_functions
+        typeset -ga preexec_functions
+
+        function precmd {
+            # vcs_info
+            # Put the string "hostname::/full/directory/path" in the title bar:
+            echo -ne "\e]2;$PWD\a"
+            # Put the parentdir/currentdir in the tab
+            echo -ne "\e]1;$PWD:h:t/$PWD:t\a"
+        }
+        function set_running_app {
+            printf "\e]1; $PWD:t:$(history $HISTCMD | cut -b7- ) \a"
+        }
+        function preexec {
+            set_running_app
+        }
+        function postexec {
+            set_running_app
+        }
+    }
+    setup_zsh_hooks;
+
+    setup_correction() {
+        setopt correct_all
+        alias man='nocorrect man'
+        alias mv='nocorrect mv'
+        alias mysql='nocorrect mysql'
+        alias mkdir='nocorrect mkdir'
+        alias erl='nocorrect erl'
+        alias curl='nocorrect curl'
+        alias rake='nocorrect rake'
+        alias make='nocorrect make'
+        alias cake='nocorrect cake'
+        alias lessc='nocorrect lessc'
+        alias lunchy='nocorrect lunchy'
+        SPROMPT="$fg[red]%R →$reset_color $fg[green]%r?$reset_color (Yes, No, Abort, Edit) "
+    }
+    setup_correction;
+
+    setup_completion() {
+        autoload -U compinit && compinit -i
+        autoload bashcompinit && bashcompinit
+        zmodload -i zsh/complist
+
+        fpath=($HOME/.zsh/compdefs $fpath)
+        fignore=(.DS_Store $fignore)
+
+        [[ -f ~/.ssh/known_hosts ]] && \
+            hosts=(`awk '{print $1}' ~/.ssh/known_hosts | tr ',' '\n' `)
+        [[ -f ~/.ssh/config ]] && \
+            hosts=($hosts `grep '^Host' ~/.ssh/config | sed s/Host\ // | egrep -v '^\*$'`)
+
+        zstyle ':completion:*' insert-tab pending
+        zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
+        zstyle ':completion:*' completer \
+            _oldlist _complete _match _approximate _prefix
+
+        zstyle ':completion:*' squeeze-slashes true
+        zstyle ':completion:*' expand 'yes'
+
+        zstyle ':completion:*' menu select=2
+
+        zstyle ':completion:*' list-colors ""
+        # zstyle ':completion:*' list-colors "di=1;34"
+        zstyle ':completion:*' format '%F{white}%d%f'
+        zstyle ':completion:*' group-name ''
+        zstyle ':completion:*' keep-prefix
+        zstyle ':completion:*' remote-access false
+
+        if [[ -d ${_zsh_user_config_dir}/cache ]]; then
+            zstyle ':completion:*' use-cache yes
+            zstyle ':completion:*' cache-path ${_zsh_user_config_dir}/cache
+        fi
+
+
+        zstyle ':completion:*:cd:*' ignore-parents parent pwd
+
+        zstyle ':completion:*:match:*' original only
+        zstyle ':completion:*:approximate:*' max-errors 1 numeric
+        zstyle ':completion:*:hosts' hosts $hosts
+
+        zstyle ':completion:sudo:*' environ PATH="$SUDO_PATH:$PATH"
+        zstyle ':completion:*:kill:*:processes' list-colors \
+            '=(#b) #([0-9]#) ([0-9a-z-]#)*=01;34=0=01'
+        zstyle ':completion:*:*:*:processes' command \
+            "ps -u `whoami` -o pid,user,comm -w -w"
+    }
+    setup_completion
+
+    # setup_modules() {
+    #     autoload -Uz is-at-least
+    #     setup_autofu() {
+    #         if is-at-least 4.3.10; then
+    #             function() {
+    #             local AUTO_FU
+    #             A=$HOME/.zsh/vendor/auto-fu.zsh/auto-fu.zsh
+    #             [[ -e "${A:r}.zwc" ]] && [[ "$A" -ot "${A:r}.zwc" ]] ||
+    #             zsh -c "source $A; auto-fu-zcompile $A ${A:h}" >/dev/null 2>&1
+    #         }
+    #             source $HOME/.zsh/vendor/auto-fu.zsh/auto-fu; auto-fu-install
+    #             zstyle ':auto-fu:highlight' input bold
+    #             zstyle ':auto-fu:highlight' completion fg=white,dim
+    #             zstyle ':auto-fu:highlight' completion/one fg=blue,dim
+    #             zstyle ':auto-fu:var' postdisplay ''
+    #             zstyle ':auto-fu:var' track-keymap-skip opp
+    #             function zle-line-init () { auto-fu-init }; zle -N zle-line-init
+    #         fi
+    #     }
+    #     setup_autofu;
+    # }
+    # setup_modules;
+
+    setup_prompt() {
+        autoload colors && colors
+        # @see `man zshcontrib`
+        autoload -Uz vcs_info
+        zstyle ':vcs_info:*' enable git hg svn
+        zstyle ':vcs_info:*' formats "(%s)-[%b]"
+        zstyle ':vcs_info:*' actionformats "(%s)-[%b|%a]"
+
+        autoload -Uz is-at-least
+        if is-at-least 4.3.10; then
+            zstyle ':vcs_info:*' check-for-changes true
+            zstyle ':vcs_info:*' stagedstr "+"
+            zstyle ':vcs_info:*' unstagedstr "-"
+            zstyle ':vcs_info:*' formats "(%s)-[%b]%c%u"
+            zstyle ':vcs_info:*' actionformats "(%s)-[%b|%a]%c%u"
+        fi
+        function _update_vcs_info_msg() {
+            psvar=()
+            LANG=en_US.UTF-8 vcs_info
+            [[ -n "$vcs_info_msg_0_" ]] && psvar[1]="$vcs_info_msg_0_"
+        }
+        add-zsh-hook precmd _update_vcs_info_msg
+        RPROMPT="%1(v|%F{green}%1v%f|)"
+
+        USER_NAME="%n"
+        HOST_NAME="%m"
+        DIR_NAME="%~"
+
+        ECHOARROW() {
+            echo "$fg_bold[black]====> $fg_no_bold[yellow]$*$reset_color"
+        }
+
+        COLLAPSED_DIR() {
+            echo $(pwd | sed -e "s,^$HOME,~,")
+            local PWD_URL="file://$HOST_NAME${PWD// /%20}"
+        }
+        PROMPT_CHAR() {
+            git branch >/dev/null 2>/dev/null && echo '±' && return
+            hg root >/dev/null 2>/dev/null && echo '☿' && return
+            echo '$'
+        }
+        VIRTUALENV_INFO() {
+            [ $VIRTUAL_ENV ] && echo ' ('`basename $VIRTUAL_ENV`')'
+        }
+    }
+    setup_prompt;
+
+    for_dumb_term() {
+        if [[ $TERM == "dumb" ]]; then
+            unsetopt zle
+            unsetopt prompt_cr
+            unsetopt prompt_subst
+            unsetopt precmd
+            unsetopt preexec
+            PS1='$ '
+        fi
+    }; for_dumb_term
+
+}; __zsh;
+
+# ALIAS
+__aliases() {
+    set_alias_common() {
+        # Common
+        alias less='less -r'
+        alias tf='tail -f'
+        alias l='less'
+        alias lh='ls -alt | head' # see the last modified files
+        alias screen='TERM=screen screen'
+        alias cl='clear'
+        alias c='cl'
+        alias gz='tar -zcvf'
+        # PS
+        alias psa="ps aux"
+        alias psg="ps aux | grep "
+        alias psr='ps aux | grep ruby'
+        # Moving around
+        alias ..='cd ..'
+        alias cdb='cd -'
+        # Show human friendly numbers and colors
+        alias df='df -h'
+        alias ll='ls -alGh'
+        alias ls='ls -Gh'
+        alias du='du -h -d 2'
+
+        alias wget='wget --user-agent=Mozilla'
+
+        alias pd="pushd"
+        alias po="popd"
+
+        alias dirs='dirs -p'
+
+
+        #enable alias to sudo command argument
+        alias sudo='sudo '
+    }
+    set_alias_common;
+
+    set_alias_edit() {
+        # editing
+        alias ,ez='vi $HOME/.zshrc'
+        alias ,sz='source $HOME/.zshrc'
+        alias ,ev='vi $HOME/.vimrc'
+        alias ,ee='vi $HOME/.emacs.d/init.el'
+    }
+    set_alias_edit;
+
+    set_alias_git() {
+        alias gs='git status'
+        alias gi='vi .gitignore'
+        alias gpsh='git push'
+        alias gsm='git submodule'
+        # alias gsmu='git submodule update'
+    }
+    set_alias_git;
+
+    set_alias_global() {
+        # Global aliases
+        alias -g L="|& $PAGER"
+        alias -g G="| grep"
+
+        if which pbcopy >/dev/null 2>&1 ; then
+            # Mac
+            alias -g C='| pbcopy'
+        elif which xsel >/dev/null 2>&1 ; then
+            # Linux
+            alias -g C='| xsel --input --clipboard'
+        elif which putclip >/dev/null 2>&1 ; then
+            # Cygwin
+            alias -g C='| putclip'
+        fi
+
+        alias -g ...='../..'
+        alias -g ....='../../..'
+        alias -g .....='../../../..'
+        alias -g C='| wc -l'
+        alias -g H='| head'
+        alias -g N='| /dev/null'
+    }
+    set_alias_global;
+}; __aliases;
+
+
+__defn() {
+    define_pyfunctions() {
+        function ppjson() {
+            python -mjson.tool;
+        }
+        function urlencode() {
+            python -c "import sys, urllib as ul; print ul.quote_plus(sys.argv[1])" $1;
+        }
+        function urldecode() {
+            python -c "import sys, urllib as ul; print ul.unquote_plus(sys.argv[1])" $1;
+        }
+        function cwd_serve() {
+            python -m SimpleHTTPServer
+        }
+        function curljson() {
+            curl -sS $@ | ppjson;
+        }
+    }; define_pyfunctions;
+
+    define_functions() {
+        function echopath() {
+            echo $PATH | tr ":" "\n"
+        }
+        function mcd() {
+            mkdir -p "$1" && cd "$1";
+        }
+        function last_modified() {
+            ls -t $* 2> /dev/null | head -n 1
+        }
+        function extract() {
+            if [[ -f $1 ]]; then
+                case $1 in
+                    *.tar.bz2) tar xvjf $1;;
+                    *.tar.gz) tar xvzf $1;;
+                    *.tar.xz) tar xvJf $1;;
+                    *.tar.lzma) tar --lzma xvf $1;;
+                    *.bz2) bunzip $1;;
+                    *.rar) unrar $1;;
+                    *.gz) gunzip $1;;
+                    *.tar) tar xvf $1;;
+                    *.tbz2) tar xvjf $1;;
+                    *.tgz) tar xvzf $1;;
+                    *.zip) unzip $1;;
+                    *.Z) uncompress $1;;
+                    *.7z) 7z x $1;;
+                    *.dmg) hdiutul mount $1;; # mount OS X disk images
+                    *) echo "'$1' could not be extracted.";;
+                esac
+            else
+                echo "'$1' is not a valid file"
+            fi
+        }
+        alias ex='extract'
+
+        function md5() {
+            echo -n $1 | openssl md5 /dev/stdin;
+        }
+        function sha1() {
+            echo -n $1 | openssl sha1 /dev/stdin;
+        }
+        function sha256() {
+            echo -n $1 | openssl dgst -sha256 /dev/stdin;
+        }
+        function sha512() {
+            echo -n $1 | openssl dgst -sha512 /dev/stdin;
+        }
+        function rot13() {
+            echo $1 | tr "A-Za-z" "N-ZA-Mn-za-m";
+        }
+
+    }; define_functions;
+
+    utility_functions() {
+        typeset -Ag FX FG BG
+        FX=(
+            reset      "%{[00m%}"
+            bold       "%{[01m%}" no-bold      "%{[22m%}"
+            italic     "%{[03m%}" no-italic    "%{[23m%}"
+            underline  "%{[04m%}" no-underline "%{[24m%}"
+            blink      "%{[05m%}" no-blink     "%{[25m%}"
+            reverse    "%{[07m%}" no-reverse   "%{[27m%}"
+        )
+        for color in {000..255}; do
+            FG[$color]="%{[38;5;${color}m%}"
+            BG[$color]="%{[48;5;${color}m%}"
+        done
+
+        function show256() {
+            for c in {000..255}; do
+            print -P -- "$c: %F{$c}O%f"
+            done
+        }
+
+        function edalias() {
+            [[ -z "$1" ]] && {
+                echo "Usage: edalias foo_alias";
+                return 1
+            } || vared aliases '[$1]';
+        }
+
+        function edfunc() {
+            [[ -z "$1" ]] && {
+                echo "Usage: edfunc foo_function";
+                return 1
+            } || zed -f "$1";
+        }
+
+        function owrite_utf8unix() {
+            if [[ -x `which nkf` ]]; then
+                nkf -w -Lu --overwrite *.txt
+                nkf -s -Lw --overwrite *.txt
+            else
+                echo "requires `nkf`."
+            fi
+        }
+        function alc() {
+            if [ -n "$1" ]; then
+                w3m "http://eow.alc.co.jp/${1}/UTF-8/?ref=sa" \
+                    | sed '1,36d' \
+                    | less
+            else
+                echo 'usage: alc word'
+            fi
+        }
+
+
+        # cd to git repository root directory
+        # http://d.hatena.ne.jp/hitode909/20100211/1265879271
+        function cdu() {
+            cd ./$(git rev-parse --show-cdup)
+            if [ $# = 1 ]; then
+                cd $1
+            fi
+        }
+
+        function pwd-clip() {
+            local copyToClipboard
+
+            if which pbcopy >/dev/null 2>&1 ; then
+            # Mac
+                copyToClipboard='pbcopy'
+            elif which xsel >/dev/null 2>&1 ; then
+            # Linux
+                copyToClipboard='xsel --input --clipboard'
+            elif which putclip >/dev/null 2>&1 ; then
+            # Cygwin
+                copyToClipboard='putclip'
+            else
+                copyToClipboard='cat'
+            fi
+
+            # ${=VAR} enables SH_WORD_SPLIT option
+            # so ${=VAR] is splited in words, for example "a" "b" "c"
+            echo -n $PWD | ${=copyToClipboard}
+        }
+
+        function scouter() {
+            sed -e '/^\s*$/d' -e '/^\s*#/d' ${ZDOTDIR:-$HOME}/.zshrc | wc -l
+        }
+
+        function make_date_dir_and_cd() {
+            local date_dir=$(date '+%Y-%m-%d')
+            if [ ! -d "$date_dir" ]; then
+                mkdir "$date_dir" || return
+            fi
+            cd "$date_dir"
+        }
+        alias ddir='make_date_dir_and_cd'
+    }
+    utility_functions;
+
+    hacks__() {
+        if [[ "$TMUX" != "" ]]; then
+            alias pbcopy='ssh 127.0.0.1 pbcopy'
+            alias pbpaste='ssh 127.0.0.1 pbpaste'
+        fi
+        [[ $EMACS = t ]] && unsetopt zle
+    }; hacks__;
+}; __defn;
+
+__compdefs() {
+    if [[ -x `which sheet` ]]; then
+        compdef _sheets sheet
+        function _sheets {
+            local -a cmds
+            _files -W ~/.sheets/ -P '~/.sheets/'
+            cmds=('list' 'edit' 'copy')
+            _describe -t commands "subcommand" cmds
+            return 1;
+        }
+    fi
+}; __compdefs;
+
+
+cdpath=(~)
+chpwd_functions=($chpwd_functions dirs)
+
+REPORTTIME=3
+
+case $(uname) in
+    *BSD|Darwin)
+        if [ -x "$(which gnuls)" ]; then
+            alias ls="gnuls"
+            alias la="ls -lhAF --color=auto"
+        else
+            alias la="ls -lhAFG"
+        fi
+        alias ps="ps -fU$(whoami)"
+        ;;
+    *)
+    alias la="ls -lhAF --color=auto"
+    alias ps="ps -fU$(whoami) --forest"
+    ;;
+esac
+
+if [ "$TMUX" != "" ]; then
+    tmux set-option status-bg \
+        colour$(($(echo -n $(whoami)@$(hostname) \
+        | sum \
+        | cut -f1 -d' ') % 8 + 8)) \
+        | cat > /dev/null
+
+# @see http://d.hatena.ne.jp/pi8027/20120227/1330349071
+#    nw vim hoge
+#    nw -dh less hoge
+
+    nw(){
+    local CMDNAME split_opts spawn_command
+    CMDNAME=`basename $0`
+
+    while getopts dhvPp:l:t:b: OPT
+    do
+        case $OPT in
+        "d" | "h" | "v" | "P" )
+            split_opts="$split_opts -$OPT";;
+        "p" | "l" | "t" )
+            split_opts="$split_opts -$OPT $OPTARG";;
+        * ) echo "Usage: $CMDNAME [-dhvP]" \
+                 "[-p percentage|-l size] [-t target-pane] [command]" 1>&2
+            return 1;;
+        esac
+    done
+    shift `expr $OPTIND - 1`
+
+    spawn_command=$@
+    [[ -z $spawn_command ]] && spawn_command=$SHELL
+
+    tmux split-window `echo -n $split_opts` "cd $PWD ; $spawn_command"
+    }
+    _nw(){
+        local args
+        args=(
+            '-d[do not make the new window become the active one]'
+            '-h[split horizontally]'
+            '-v[split vertically]'
+            '-l[define new pane'\''s size]: :_guard "[0-9]#" "numeric value"'
+            '-p[define new pane'\''s size in percent]: :_guard "[0-9]#" "numeric value"'
+            '-t[choose target pane]: :_guard "[0-9]#" "numeric value"'
+        '*:: :_normal'
+        )
+        _arguments ${args} && return
+    }
+    compdef _nw nw
+fi
+
+cx() {
+    chmod +x $*
+}
+
+randline() {
+    integer z="$(wc -l <$1)"
+    sed -n $[RANDOM%z+1]p $1
+}
+if exists percol; then
+    function ppgrep() {
+        if [[ $1 == "" ]]; then
+            PERCOL=percol
+        else
+            PERCOL="percol --query $1"
+        fi
+        ps aux | eval $PERCOL | awk '{ print $2 }'
+    }
+    function ppkill() {
+        if [[ $1 =~ "^-" ]]; then
+            QUERY=""            # options only
+        else
+            QUERY=$1            # with a query
+            shift
+        fi
+        ppgrep $QUERY | xargs kill $*
+    }
+    function percol_select_history() {
+        local tac
+        exists gtac && tac=gtac || tac=tac
+        BUFFER=$($tac $HISTFILE | sed 's/^: [0-9]*:[0-9]*;//' | percol --query "$LBUFFER")
+        CURSOR=$#BUFFER         # move cursor
+        zle -R -c               # refresh
+    }
+
+    zle -N percol_select_history
+    bindkey '^R' percol_select_history
+fi
+typeset -Ag abbreviations
+abbreviations=(
+  "G "    "| grep"
+  "S "    "| sort"
+  "L "    "| $PAGER"
+  "H "    "| head"
+  "T "    "| tail"
+  "W "    "| wc"
+)
+
+magic-abbrev-expand() {
+    local MATCH
+    LBUFFER=${LBUFFER%%(#m)[_a-zA-Z0-9]#}
+    LBUFFER+=${abbreviations[$MATCH]:-$MATCH}
+    zle self-insert
+}
+no-magic-abbrev-expand() {
+  LBUFFER+=' '
+}
+zle -N magic-abbrev-expand
+zle -N no-magic-abbrev-expand
+bindkey " " magic-abbrev-expand
+bindkey "^x " no-magic-abbrev-expand
+bindkey -M isearch " " self-insert
+
+function ft_accept_line_cd_up() {
+    setopt local_options extended_glob
+    local -a cmdline
+    cmdline=( ${(z)BUFFER} )
+    if (( ${#cmdline} == 1 )) && [[ ${cmdline[1]} == .# ]] ; then
+        BUFFER='cd '
+        for (( i = 1; i <= ${#${cmdline[1]}}; i++ )); do
+            BUFFER="${BUFFER}../"
+        done
+        BUFFER=${BUFFER%/}
+    fi
+    zle ".$WIDGET"
+}
+zle -N accept-line ft_accept_line_cd_up
+
+function ft_complete_with_dots() {
+    setopt local_options extended_glob
+    local -a cmdline
+    cmdline=( ${(z)BUFFER} )
+    if (( ${#cmdline} == 1 )) && [[ ${cmdline[1]} == .# ]] ; then
+        BUFFER='cd '
+        for (( i = 1; i <= ${#${cmdline[1]}}; i++ )); do
+            BUFFER="${BUFFER}../"
+        done
+        CURSOR=${#BUFFER}
+    fi
+    zle ".$WIDGET"
+}
+zle -N complete-word ft_complete_with_dots
+# if you don't do this already...
+bindkey '^I' complete-word
+
+function printsetoptions() {
+    printf '%s=%s\n' "${(@kv)options}"
+}
+
+function vnice() {
+    if [[ -z "$1" ]] ; then
+        echo "vnice [ <pid>... | <program> ]" >&2
+        return 1
+    elif [[ "$1" =~ ^[0-9]+$ ]] ; then
+        while [[ "$1" =~ ^[0-9]+$ ]] ; do
+            ionice -n7 -p $1
+            renice 20 $1
+            shift
+        done
+    else
+        ionice -n7 nice -n20 $@
+    fi
+}
+
+# To use pbcopy/pbpaste with UTF-8 encoding.
+export __CF_USER_TEXT_ENCODING=${__CF_USER_TEXT_ENCODING/:*:/:0x08000100:}
+
+export GISTY_ACCESS_TOKEN=a76fa3a7ca85b477bfa8bbd1a1fec0f000a97e24
+export GISTY_DIR="$HOME/etc/gists"
+
+typeset -gxU PATH=$PATH # remove dupes in path
+unset _zsh_user_config_dir
+
+
+# __END__
+# vim: filetype=zsh