zsh, fix ls color issue on mac and linux
[dotfiles.git] / zsh / zshrc
1 #!/bin/zsh
2 #
3 # Darwin or Linux
4 OSNAME=`uname` 
5
6 autoload colors
7 colors
8
9 for color in RED GREEN YELLOW BLUE MAGENTA CYAN WHITE; do
10 eval _$color='%{$terminfo[bold]$fg[${(L)color}]%}'
11 eval $color='%{$fg[${(L)color}]%}'
12 (( count = $count + 1 ))
13 done
14
15
16 # right prompt
17 #RPROMPT=$(echo "$RED%D %T$FINISH")
18 #PROMPT=$(echo "$CYAN%n[$BLUE%~]$_YELLOW>>$FINISH ")
19 PROMPT=$(echo "%B$CYAN%n$_YELLOW@$BLUE%<<[%~%<<]$_YELLOW>> $WHITE%b")
20
21 export HISTSIZE=10000
22 export SAVEHIST=10000
23 export HISTFILE="$HOME/.zsh_history"
24 setopt INC_APPEND_HISTORY
25 setopt HIST_IGNORE_DUPS
26 setopt EXTENDED_HISTORY
27
28 setopt AUTO_PUSHD       
29 setopt HIST_IGNORE_SPACE
30
31
32
33 export CLICOLOR=1
34 export LSCOLORS=ExFxCxDxBxegedabagaced
35
36         
37
38 man() {
39         env \
40                 GROFF_NO_SGR=$(printf "1")      \
41                 LESS_TERMCAP_mb=$(printf "\e[1;31m") \
42                 LESS_TERMCAP_md=$(printf "\e[1;31m") \
43                 LESS_TERMCAP_me=$(printf "\e[0m") \
44                 LESS_TERMCAP_se=$(printf "\e[0m") \
45                 LESS_TERMCAP_so=$(printf "\e[1;44;33m") \
46                 LESS_TERMCAP_ue=$(printf "\e[0m") \
47                 LESS_TERMCAP_us=$(printf "\e[1;32m") \
48                         man "$@"
49 }
50
51
52 export PYTHONPATH="/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/"
53 export DEV_ENV_ROOT=$HOME/android/
54 export ANDROID_NDK_ROOT="${DEV_ENV_ROOT}/android-ndk-r10d/"
55 export ANDROID_SDK_ROOT="${DEV_ENV_ROOT}/android-sdk-macosx/"
56 #export ANDROID_TOOLCHAIN="${DEV_ENV_ROOT}/standalone-toolchain-api14/"
57 export ANDROID_NDK_HOME="$HOME/android/android-ndk-r10d"
58
59
60
61 export ANDROID_TOOLCHAIN="$ANDROID_NDK_HOME/standalone-toolchain-api14/"
62
63
64 export ANDROID_HOME="$HOME/android/android-sdk-macosx/"
65
66 export PATH=$PATH:"${ANDROID_TOOLCHAIN}/bin/":"${ANDROID_HOME}/platform-tools/"
67 export PATH="$HOME/bin":"/usr/local/bin":$PATH
68
69 LS_COLORS="rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:"
70 #export LS_COLORS
71 ###====================
72 #
73 #autoload -U compinit
74 #compinit
75 #zstyle ':completion:*:descriptions' format '%U%B%d%b%u'
76 #zstyle ':completion:*:warnings' format '%BSorry, no matches for: %d%b'
77 #
78 #
79 #
80 # Use modern completion system
81 autoload -Uz compinit
82 compinit
83
84 zstyle ':completion:*' auto-description 'specify: %d'
85 zstyle ':completion:*' completer _expand _complete _correct _approximate
86 #zstyle ':completion:*' format 'Completing %d'
87 zstyle ':completion:*' group-name ''
88 zstyle ':completion:*' menu select=2
89 #eval "$(dircolors -b)"
90 zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
91 zstyle ':completion:*' list-colors ''
92 zstyle ':completion:*' list-prompt %SAt %p: Hit TAB for more, or the character to insert%s
93 zstyle ':completion:*' matcher-list '' 'm:{a-z}={A-Z}' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=* l:|=*'
94 zstyle ':completion:*' menu select=long
95 zstyle ':completion:*' select-prompt %SScrolling active: current selection at %p%s
96 zstyle ':completion:*' use-compctl false
97 zstyle ':completion:*' verbose true
98
99 zstyle ':completion:*:*:kill:*:processes' list-colors '=(#b) #([0-9]#)*=0=01;31'
100 zstyle ':completion:*:kill:*' command 'ps -u $USER -o pid,%cpu,tty,cputime,cmd'
101
102
103 ######################## zsh alias #########################
104
105 alias grep='grep --color -E'
106 #alias mvim='mvim --remote-silent'
107 #alias vim='/usr/local/bin/mvim -v'
108 alias tmux='tmux -2'
109
110 if [[ $OSNAME == 'Darwin' ]]; then
111     alias l='ls -l'
112     alias ll='ls -l'
113     alias la='ls -a'
114 elif [[ $OSNAME == 'Linux' ]]; then
115     alias l='ls -l --color=auto'
116     alias ll='ls -l --color=auto'
117     alias la='ls -a --color=auto'
118     alias ls='ls --color=auto'
119 fi
120
121 alias diff='colordiff'
122
123 alias mv='mv -i'
124 alias cp='cp -i'
125 alias ln='ln -i'
126
127 #alias svn='colorsvn'
128 alias sed='/usr/local/bin/gsed'
129
130 alias 'git-log'='git log  --oneline --graph --all --color --decorate --abbrev-commit'
131
132
133
134 ###########################  zsh completion ##########################
135 #
136 #autoload -U compinit
137 #compinit
138
139 #zstyle ':completion:*:descriptions' format '%U%B%d%b%u'
140 #zstyle ':completion:*:warnings' format '%BSorry, no matches for: %d%b'
141 #
142 #autoload -U compinit
143 #compinit
144 #
145 #autoload -U promptinit
146 #promptinit
147 #
148 #setopt correctall
149 #
150 #
151 zstyle ':completion:*' menu select
152 setopt AUTOLIST
153 setopt AUTOMENU
154
155
156 autoload -U compinit
157 compinit
158
159
160 WORDCHARS='*?_-[]~=&;!#$%^(){}<>'
161
162
163 ################
164 #
165 #http://techanic.net/2012/12/30/my_git_prompt_for_zsh.html
166 # Adapted from code found at <https://gist.github.com/1712320>.
167
168 setopt prompt_subst
169 autoload -U colors && colors # Enable colors in prompt
170
171 # Modify the colors and symbols in these variables as desired.
172 GIT_PROMPT_SYMBOL="%{$fg[blue]%}±"
173 GIT_PROMPT_PREFIX="%{$fg[green]%}[%{$reset_color%}"
174 GIT_PROMPT_SUFFIX="%{$fg[green]%}]%{$reset_color%}"
175 GIT_PROMPT_AHEAD="%{$fg[red]%}ANUM%{$reset_color%}"
176 GIT_PROMPT_BEHIND="%{$fg[cyan]%}BNUM%{$reset_color%}"
177 GIT_PROMPT_MERGING="%{$fg_bold[magenta]%}⚡︎%{$reset_color%}"
178 GIT_PROMPT_UNTRACKED="%{$fg_bold[red]%}•%{$reset_color%}"
179 GIT_PROMPT_MODIFIED="%{$fg_bold[yellow]%}•%{$reset_color%}"
180 GIT_PROMPT_STAGED="%{$fg_bold[green]%}•%{$reset_color%}"
181
182 # Show Git branch/tag, or name-rev if on detached head
183 parse_git_branch() {
184   (git symbolic-ref -q HEAD || git name-rev --name-only --no-undefined --always HEAD) 2> /dev/null
185 }
186
187 # Show different symbols as appropriate for various Git repository states
188 parse_git_state() {
189
190   # Compose this value via multiple conditional appends.
191   local GIT_STATE=""
192
193   local NUM_AHEAD="$(git log --oneline @{u}.. 2> /dev/null | wc -l | tr -d ' ')"
194   if [ "$NUM_AHEAD" -gt 0 ]; then
195     GIT_STATE=$GIT_STATE${GIT_PROMPT_AHEAD//NUM/$NUM_AHEAD}
196   fi
197
198   local NUM_BEHIND="$(git log --oneline ..@{u} 2> /dev/null | wc -l | tr -d ' ')"
199   if [ "$NUM_BEHIND" -gt 0 ]; then
200     GIT_STATE=$GIT_STATE${GIT_PROMPT_BEHIND//NUM/$NUM_BEHIND}
201   fi
202
203   local GIT_DIR="$(git rev-parse --git-dir 2> /dev/null)"
204   if [ -n $GIT_DIR ] && test -r $GIT_DIR/MERGE_HEAD; then
205     GIT_STATE=$GIT_STATE$GIT_PROMPT_MERGING
206   fi
207
208   if [[ -n $(git ls-files --other --exclude-standard 2> /dev/null) ]]; then
209     GIT_STATE=$GIT_STATE$GIT_PROMPT_UNTRACKED
210   fi
211
212   if ! git diff --quiet 2> /dev/null; then
213     GIT_STATE=$GIT_STATE$GIT_PROMPT_MODIFIED
214   fi
215
216   if ! git diff --cached --quiet 2> /dev/null; then
217     GIT_STATE=$GIT_STATE$GIT_PROMPT_STAGED
218   fi
219
220   if [[ -n $GIT_STATE ]]; then
221     echo "$GIT_PROMPT_PREFIX$GIT_STATE$GIT_PROMPT_SUFFIX"
222   fi
223
224 }
225
226 # If inside a Git repository, print its branch and state
227 git_prompt_string() {
228   local git_where="$(parse_git_branch)"
229   [ -n "$git_where" ] && echo "$GIT_PROMPT_SYMBOL$(parse_git_state)$GIT_PROMPT_PREFIX%{$fg[yellow]%}${git_where#(refs/heads/|tags/)}$GIT_PROMPT_SUFFIX"
230 }
231
232 # Set the right-hand prompt
233 RPS1='$(git_prompt_string)'
234
235 #source ~/Private/zsh-syntax-highlighting/zsh-syntax-highlighting.plugin.zsh
236 # [[ -f  "~/.zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" ]] && 
237 source ~/.zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
238 # http://stackoverflow.com/questions/3483604/which-shortcut-in-zsh-does-the-same-as-ctrl-u-in-bash
239 bindkey \^U backward-kill-line
240
241 export PYTHONSTARTUP="$HOME/.pythonrc"
242
243 export ZSHHOME="$HOME/.zsh"
244 [[ -f "$ZSHHOME/cpverc" ]] && . "$ZSHHOME/cpverc"
245 [[ -f "$ZSHHOME/eccrc" ]] && . "$ZSHHOME/eccrc"
246
247
248 #` git log --oneline --abbrev-commit --all --graph --decorate --color `
249 `which brew`  &> /dev/null
250 if [ $? -eq 0 ]; then
251         [[ -s `brew --prefix`/etc/autojump.sh ]] && . `brew --prefix`/etc/autojump.sh
252 fi
253
254 alias emacs='TERM=xterm-256color emacs -nw'
255
256 alias tw='open -a /Applications/TextWrangler.app/'
257
258 #
259 #function exists { which $1 &> /dev/null }
260 #
261 #if exists percol; then
262 #    function percol_select_history() {
263 #        local tac
264 #        exists gtac && tac="gtac" || { exists tac && tac="tac" || { tac="tail -r" } }
265 #        BUFFER=$(fc -l -n 1 | eval $tac | percol --query "$LBUFFER")
266 #        CURSOR=$#BUFFER         # move cursor
267 #        zle -R -c               # refresh
268 #    }
269 #
270 #    zle -N percol_select_history
271 #    bindkey '^R' percol_select_history
272 #fi
273 export LANG='en_US.UTF-8'
274 export LC_ALL="en_US.UTF-8"
275
276 lftp-cp() {
277
278     server='cmbu-ftp.cisco.com'
279     user='cmbu'
280     pass='cisco123!@#'
281     home='/FTPServer/users/peli3'
282     dir=`date +%m%d`
283
284     localfile=$1;
285     remotefile=${home}/${dir}/$2;
286
287     echo "copy ${localfile} to ftp://${server}${remotefile}"
288     lftp -e "mkdir ${home}/${dir}; put ${localfile} -o  ${remotefile}; bye" -u $user,$pass $server
289 }
290 merge_logs() {
291     ls -rl jabber.log*  | awk '{print $9}' | Xargs cat >> full.log
292 }
293
294 export MANPATH=$MANPATH:/usr/local/man
295
296
297 ## vim YouCompleteMe
298 # https://github.com/Valloric/YouCompleteMe/issues/18
299 #export DYLD_FORCE_FLAT_NAMESPACE=1
300
301 ## appended by cpan initializaion
302 PATH="/Users/peli3/perl5/bin${PATH:+:${PATH}}"; export PATH;
303 PERL5LIB="/Users/peli3/perl5/lib/perl5${PERL5LIB:+:${PERL5LIB}}"; export PERL5LIB;
304 PERL_LOCAL_LIB_ROOT="/Users/peli3/perl5${PERL_LOCAL_LIB_ROOT:+:${PERL_LOCAL_LIB_ROOT}}"; export PERL_LOCAL_LIB_ROOT;
305 PERL_MB_OPT="--install_base \"/Users/peli3/perl5\""; export PERL_MB_OPT;
306 PERL_MM_OPT="INSTALL_BASE=/Users/peli3/perl5"; export PERL_MM_OPT;
307
308
309
310
311 export MANPATH=$MANPATH:${HOME}/perl5/man
312
313 export PATH=$PATH:"${HOME}/scripts"
314 ## hunspell path
315 export DICPATH="/usr/local/share/hunspell/"