emacs - magit related change
[dotfiles.git] / zsh / zshrc
1 #!/bin/zsh
2 autoload colors
3 colors
4
5 for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
6 eval _$color='%{$terminfo[bold]$fg[${(L)color}]%}'
7 eval $color='%{$fg[${(L)color}]%}'
8 (( count = $count + 1 ))
9 done
10
11
12 # right prompt
13 #RPROMPT=$(echo "$RED%D %T$FINISH")
14 #PROMPT=$(echo "$CYAN%n[$BLUE%~]$_YELLOW>>$FINISH ")
15 PROMPT=$(echo "%B$CYAN%n$_YELLOW@$BLUE%<<[%~%<<]$_YELLOW>> $WHITE%b")
16
17 export HISTSIZE=10000
18 export SAVEHIST=10000
19 export HISTFILE="$HOME/.zsh_history"
20 setopt INC_APPEND_HISTORY
21 setopt HIST_IGNORE_DUPS
22 setopt EXTENDED_HISTORY
23
24 setopt AUTO_PUSHD       
25 setopt HIST_IGNORE_SPACE
26
27
28
29 export CLICOLOR=1
30 export LSCOLORS=ExFxCxDxBxegedabagaced
31
32         
33
34 man() {
35         env \
36                 GROFF_NO_SGR=$(printf "1")      \
37                 LESS_TERMCAP_mb=$(printf "\e[1;31m") \
38                 LESS_TERMCAP_md=$(printf "\e[1;31m") \
39                 LESS_TERMCAP_me=$(printf "\e[0m") \
40                 LESS_TERMCAP_se=$(printf "\e[0m") \
41                 LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
42                 LESS_TERMCAP_ue=$(printf "\e[0m") \
43                 LESS_TERMCAP_us=$(printf "\e[1;32m") \
44                         man "$@"
45 }
46
47
48 export PYTHONPATH="/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/"
49 export DEV_ENV_ROOT=$HOME/android/
50 export ANDROID_NDK_ROOT="${DEV_ENV_ROOT}/android-ndk-r10d/"
51 export ANDROID_SDK_ROOT="${DEV_ENV_ROOT}/android-sdk-macosx/"
52 #export ANDROID_TOOLCHAIN="${DEV_ENV_ROOT}/standalone-toolchain-api14/"
53 export ANDROID_NDK_HOME="$HOME/android/android-ndk-r10d"
54
55
56
57 export ANDROID_TOOLCHAIN="$ANDROID_NDK_HOME/standalone-toolchain-api14/"
58
59
60 export ANDROID_HOME="$HOME/android/android-sdk-macosx/"
61
62 export PATH=$PATH:"${ANDROID_TOOLCHAIN}/bin/":"${ANDROID_HOME}/platform-tools/"
63 export PATH="$HOME/bin":"/usr/local/bin":$PATH
64
65 ###====================
66 #
67 #autoload -U compinit
68 #compinit
69 #zstyle ':completion:*:descriptions' format '%U%B%d%b%u'
70 #zstyle ':completion:*:warnings' format '%BSorry, no matches for: %d%b'
71 #
72 #
73 ######################## zsh alias #########################
74
75 alias grep='grep --color -E'
76 #alias mvim='mvim --remote-silent'
77 #alias vim='/usr/local/bin/mvim -v'
78 alias tmux='tmux -2'
79
80 alias l='ls -l'
81 alias ll='ls -l'
82 alias la='ls -a'
83
84 alias diff='colordiff'
85
86 alias mv='mv -i'
87 alias cp='cp -i'
88 alias ln='ln -i'
89
90 #alias svn='colorsvn'
91 alias sed='/usr/local/bin/gsed'
92
93 alias 'git log'='git log  --oneline --graph --all --color --decorate --abbrev-commit'
94
95
96
97 ###########################  zsh completion ##########################
98 #
99 #autoload -U compinit
100 #compinit
101
102 #zstyle ':completion:*:descriptions' format '%U%B%d%b%u'
103 #zstyle ':completion:*:warnings' format '%BSorry, no matches for: %d%b'
104 #
105 #autoload -U compinit
106 #compinit
107 #
108 #autoload -U promptinit
109 #promptinit
110 #
111 #setopt correctall
112 #
113 #
114 zstyle ':completion:*' menu select
115 setopt AUTOLIST
116 setopt AUTOMENU
117
118
119 autoload -U compinit
120 compinit
121
122
123 WORDCHARS='*?_-[]~=&;!#$%^(){}<>'
124
125
126 ################
127 #
128 #http://techanic.net/2012/12/30/my_git_prompt_for_zsh.html
129 # Adapted from code found at <https://gist.github.com/1712320>.
130
131 setopt prompt_subst
132 autoload -U colors && colors # Enable colors in prompt
133
134 # Modify the colors and symbols in these variables as desired.
135 GIT_PROMPT_SYMBOL="%{$fg[blue]%}±"
136 GIT_PROMPT_PREFIX="%{$fg[green]%}[%{$reset_color%}"
137 GIT_PROMPT_SUFFIX="%{$fg[green]%}]%{$reset_color%}"
138 GIT_PROMPT_AHEAD="%{$fg[red]%}ANUM%{$reset_color%}"
139 GIT_PROMPT_BEHIND="%{$fg[cyan]%}BNUM%{$reset_color%}"
140 GIT_PROMPT_MERGING="%{$fg_bold[magenta]%}⚡︎%{$reset_color%}"
141 GIT_PROMPT_UNTRACKED="%{$fg_bold[red]%}•%{$reset_color%}"
142 GIT_PROMPT_MODIFIED="%{$fg_bold[yellow]%}•%{$reset_color%}"
143 GIT_PROMPT_STAGED="%{$fg_bold[green]%}•%{$reset_color%}"
144
145 # Show Git branch/tag, or name-rev if on detached head
146 parse_git_branch() {
147   (git symbolic-ref -q HEAD || git name-rev --name-only --no-undefined --always HEAD) 2> /dev/null
148 }
149
150 # Show different symbols as appropriate for various Git repository states
151 parse_git_state() {
152
153   # Compose this value via multiple conditional appends.
154   local GIT_STATE=""
155
156   local NUM_AHEAD="$(git log --oneline @{u}.. 2> /dev/null | wc -l | tr -d ' ')"
157   if [ "$NUM_AHEAD" -gt 0 ]; then
158     GIT_STATE=$GIT_STATE${GIT_PROMPT_AHEAD//NUM/$NUM_AHEAD}
159   fi
160
161   local NUM_BEHIND="$(git log --oneline ..@{u} 2> /dev/null | wc -l | tr -d ' ')"
162   if [ "$NUM_BEHIND" -gt 0 ]; then
163     GIT_STATE=$GIT_STATE${GIT_PROMPT_BEHIND//NUM/$NUM_BEHIND}
164   fi
165
166   local GIT_DIR="$(git rev-parse --git-dir 2> /dev/null)"
167   if [ -n $GIT_DIR ] && test -r $GIT_DIR/MERGE_HEAD; then
168     GIT_STATE=$GIT_STATE$GIT_PROMPT_MERGING
169   fi
170
171   if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
172     GIT_STATE=$GIT_STATE$GIT_PROMPT_UNTRACKED
173   fi
174
175   if ! git diff --quiet 2> /dev/null; then
176     GIT_STATE=$GIT_STATE$GIT_PROMPT_MODIFIED
177   fi
178
179   if ! git diff --cached --quiet 2> /dev/null; then
180     GIT_STATE=$GIT_STATE$GIT_PROMPT_STAGED
181   fi
182
183   if [[ -n $GIT_STATE ]]; then
184     echo "$GIT_PROMPT_PREFIX$GIT_STATE$GIT_PROMPT_SUFFIX"
185   fi
186
187 }
188
189 # If inside a Git repository, print its branch and state
190 git_prompt_string() {
191   local git_where="$(parse_git_branch)"
192   [ -n "$git_where" ] && echo "$GIT_PROMPT_SYMBOL$(parse_git_state)$GIT_PROMPT_PREFIX%{$fg[yellow]%}${git_where#(refs/heads/|tags/)}$GIT_PROMPT_SUFFIX"
193 }
194
195 # Set the right-hand prompt
196 RPS1='$(git_prompt_string)'
197
198 #source ~/Private/zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh
199 source ~/.zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
200 # http://stackoverflow.com/questions/3483604/which-shortcut-in-zsh-does-the-same-as-ctrl-u-in-bash
201 bindkey \^U backward-kill-line
202
203 export PYTHONSTARTUP="$HOME/.pythonrc"
204
205 export ZSHHOME="$HOME/.zsh"
206 [[ -f "$ZSHHOME/cpverc" ]] && . "$ZSHHOME/cpverc"
207 [[ -f "$ZSHHOME/eccrc" ]] && . "$ZSHHOME/eccrc"
208
209
210 #` git log --oneline --abbrev-commit --all --graph --decorate --color `
211 [[ -s `brew --prefix`/etc/autojump.sh ]] && . `brew --prefix`/etc/autojump.sh
212
213 alias emacs='TERM=xterm-256color emacs -nw'
214
215 alias tw='open -a /Applications/TextWrangler.app/'
216
217 #
218 #function exists { which $1 &> /dev/null }
219 #
220 #if exists percol; then
221 #    function percol_select_history() {
222 #        local tac
223 #        exists gtac && tac="gtac" || { exists tac && tac="tac" || { tac="tail -r" } }
224 #        BUFFER=$(fc -l -n 1 | eval $tac | percol --query "$LBUFFER")
225 #        CURSOR=$#BUFFER         # move cursor
226 #        zle -R -c               # refresh
227 #    }
228 #
229 #    zle -N percol_select_history
230 #    bindkey '^R' percol_select_history
231 #fi
232 export LANG='en_US.UTF-8'
233 export LC_ALL="en_US.UTF-8"