public
Description: home and config
Homepage: qiukun.is-programmer.com
Clone URL: git://github.com/qiukun/hmandcon.git
qiukun (author)
Sun Oct 11 00:37:14 -0700 2009
commit  327db301927e307afc3497c744f62245627fabe3
tree    9b7ec6e53664069b795bb12b2f955984b9b073d4
parent  80961deea6bba4f821782d038093ee3dde7765a7
hmandcon / .zshrc
100644 315 lines (290 sloc) 12.036 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#!/bin/zsh
 
#------------------------listing color----------------------------------
if [[ "$TERM" == *256color ]] || [[ "$TERM" = screen ]]; then
    #use prefefined colors
    eval $(dircolors -b $HOME/.lscolor256)
else
    eval $(dircolors -b $HOME/.lscolor)
fi
 
#---------------------------options-------------------------------------
setopt complete_aliases #do not expand aliases _before_ completion has finished
setopt auto_cd # if not a command, try to cd to it.
setopt auto_pushd # automatically pushd directories on dirstack
setopt pushd_ignore_dups # do not push dups on stack
setopt pushd_silent # be quiet about pushds and popds
setopt brace_ccl # expand alphabetic brace expressions
#setopt chase_links # ~/ln -> /; cd ln; pwd -> /
setopt complete_in_word # stays where it is and completion is done from both ends
setopt correct # spell check for commands only
#setopt equals extended_glob # use extra globbing operators
setopt hash_list_all # search all paths before command completion
setopt hist_ignore_all_dups # when runing a command several times, only store one
setopt hist_reduce_blanks # reduce whitespace in history
setopt share_history # share history among sessions
setopt hist_verify # reload full command when runing from history
setopt hist_expire_dups_first #remove dups when max size reached
setopt interactive_comments # why not?
setopt list_types # show ls -F style marks in file completion
setopt long_list_jobs # show pid in bg job list
setopt numeric_glob_sort # when globbing numbered files, use real counting
setopt inc_append_history # append to history once executed
 
#remove / and . from WORDCHARS to allow alt-backspace to delete word
#WORDCHARS='*?_-[]~=&;!#$%^(){}<>'
 
#replace the default beep with a message
#ZBEEP='~/MACSound/System\ Notifi.wav'
#-------------------------completion system-----------------------------
zmodload -i zsh/complist
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*:*:kill:*' list-colors '=%*=01;31'
#ignore list in completion
zstyle ':completion:*' ignore-parents parent pwd directory
#menu selection in completion
zstyle ':completion:*' menu select=1
#zstyle ':completion:*' completer _complete _match _approximate
zstyle ':completion:*' completer _complete _match _user_expand
zstyle ':completion:*:match:*' original only
zstyle ':completion:*' user-expand _pinyin
zstyle ':completion:*:approximate:*' max-errors 1 numeric
## case-insensitive (uppercase from lowercase) completion
zstyle ':completion:*' matcher-list 'm:{[:lower:]}={[:upper:]}'
### case-insensitive (all) completion
#zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
#kill completion
zstyle ':completion:*:*:kill:*' menu yes select
zstyle ':completion:*:*:*:*:processes' force-list always
zstyle ':completion:*:processes' command 'ps -au$USER'
#use cache to speed up pacman completion
zstyle ':completion::complete:*' use-cache on
#zstyle ':completion::complete:*' cache-path .zcache
#group matches and descriptions
zstyle ':completion:*:matches' group 'yes'
zstyle ':completion:*' group-name ''
zstyle ':completion:*:options' description 'yes'
zstyle ':completion:*:options' auto-description '%d'
zstyle ':completion:*:descriptions' format $'\e[01;33m -- %d --\e[0m'
zstyle ':completion:*:messages' format $'\e[01;35m -- %d --\e[0m'
zstyle ':completion:*:warnings' format $'\e[01;31m -- No Matches Found :( --\e[0m'
zstyle ':completion:*:corrections' format $'\e[0;31m -- %d (errors: %e) --\e[0m'
 
#autoload -U compinit
autoload -Uz compinit
compinit
 
#---------------------------prompt--------------------------------------
#autoload -U promptinit zmv
#promptinit
if [ "$SSH_TTY" = "" ]; then
    local host="%B%F{magenta}%m%f%b"
else
    local host="%B%F{red}%m%f%b"
fi
local user="%B%(!:%F{red}:%F{green})%n%f%b" #different color for privileged sessions
local symbol="%B%(!:%F{red}# :%F{yellow}> )%f%b"
local job="%1(j,%F{red}:%F{blue}%j,)%f%b"
export PROMPT=$user"%F{yellow}@%f"$host$job$symbol
#export RPROMPT="%{$fg_no_bold[${1:-magenta}]%}%~%{$reset_color%}"
export RPROMPT="%F{magenta}%~%f"
 
# SPROMPT - the spelling prompt
export SPROMPT="zsh: correct '%F{red}%B%R%f%b' to '%F{green}%B%r%f%b' ? ([Y]es/[N]o/[E]dit/[A]bort) "
 
#---------------------------history-------------------------------------
# number of lines kept in history
export HISTSIZE=10000
# number of lines saved in the history after logout
export SAVEHIST=10000
# location of history
export HISTFILE=$HOME/.zsh_history
 
#---------------------------alias---------------------------------------
# alias and listing colors
export GREP_COLOR='31;1'
alias grep='grep -I --color=always'
alias egrep='egrep -I --color=always'
alias cal='cal -3m'
alias ls='ls -h --color=auto -X --time-style="+[%Y-%m-%d %k:%M]"'
alias vi='vim'
alias ll='ls -l'
alias df='df -Th'
alias du='du -h'
alias mkdir='nocorrect mkdir'
#show directories size
alias dud='du -s *(/)'
#alias which='alias | /usr/bin/which --read-alias'
alias pyprof='python -m cProfile'
alias ri='ri -f ansi'
alias history='history 1' #zsh specific
#alias mplayer='mplayer -cache 512'
alias zhcon='zhcon --utf8'
alias vless="/usr/share/vim/macros/less.sh"
del() {mv -vif -- $* ~/.Trash}
alias m='mutt'
alias port='netstat -ntlp' #opening ports
alias e264='mencoder -vf harddup -ovc x264 -x264encopts crf=22:subme=5:frameref=2:8x8dct:bframes=3:weight_b:b_pyramid -oac mp3lame -lameopts aq=7:mode=0:vol=1.2:vbr=2:q=6 -srate 32000'
#alias tree="tree --dirsfirst"
alias top10='print -l ${(o)history%% *} | uniq -c | sort -nr | head -n 10'
#alias tree="ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'"
#alias tt="vim +'set spell' ~/doc/TODO.otl"
#alias mlychee="sshfs -p 2023 roy@lychee: /home/roylez/remote/lychee"
#alias gfw="ssh -CNfg -D 7777 -l roy lychee &>/dev/null &"
#alias rtm="twitter d rtm"
#alias rtorrent="screen rtorrent"
#if [ "$HOSTNAME" != 'lychee' ]; then
# for i in showq qstat qdel qnodes showstart; do
# alias $i="ssh roy@lychee -p 2023 /opt/bin/$i"
# done
# function qsub(){ssh roy@lychee -p 2023 "cd ${(S)PWD#lez/remote/lychee};/opt/bin/qsub -o /tmp -e /tmp $1"}
#fi
[ -x /usr/bin/pal ] && alias pal="pal -r 0-7 --color"
[ -x /usr/bin/cdf ] && alias df="cdf -h"
if [ -x /usr/bin/grc ]; then
    alias cl="/usr/bin/grc -es --colour=auto"
    for i in diff cat make gcc g++ as gas ld netstat ping traceroute; do
        alias $i="cl $i"
    done
fi
alias -g A="|awk"
alias -g C="|wc"
alias -g E="|sed"
alias -g G="|grep"
alias -g H="|head"
alias -g L="|less"
alias -g S="|sort"
alias -g T="|tail"
alias -g X="|xargs"
 
#-----------------user defined functions--------------------------------
#show 256 color tab
#256tab() {
# for k in `seq 0 1`;do
# for j in `seq $((16+k*18)) 36 $((196+k*18))`;do
# for i in `seq $j $((j+17))`; do
# printf "\e[01;$1;38;5;%sm%4s" $i $i;
# done;echo;
# done;
# done
#}
 
#alarm() {
# echo "msg ${argv[2,-1]} && aplay -q ~/.sounds/MACSound/System\ Notifi.wav" | at now + $1 min
#}
#-----------------functions to set gnu screen title----------------------
# active command as title in terminals
case $TERM in
    xterm*|rxvt*)
    function title()
    {
        #print -nP '\e]0;'$*'\a'
        print -nPR $'\033]0;'$1$'\a'
    } ;;
    screen*)
    function title()
    {
        #modify screen title
        print -nPR $'\033k'$1$'\033'\\
        #modify window title bar
        #print -nPR $'\033]0;'$2$'\a'
    } ;;
    *)
    function title() {}
    ;;
esac
 
#set screen title if not connected remotely
#if [ "$STY" != "" ]; then
function precmd {
    #title "`print -Pn "%~" | sed "s:\([~/][^/]*\)/.*/:\1...:"`" "$TERM $PWD"
    title "`print -Pn "%~" |sed "s:\([~/][^/]*\)/.*/:\1...:;s:\([^-]*-[^-]*\)-.*:\1:"`" "$TERM $PWD"
    echo -ne '\033[?17;0;127c'
}
 
function preexec {
    emulate -L zsh
    local -a cmd; cmd=(${(z)1})
    if [[ $cmd[1]:t == "ssh" ]]; then
        title "@""`echo $cmd[2]|sed 's:.*@::'`" "$TERM $cmd"
    elif [[ $cmd[1]:t == "sudo" ]]; then
        title "#"$cmd[2]:t "$TERM $cmd[3,-1]"
    elif [[ $cmd[1]:t == "for" ]]; then
        title "()"$cmd[7] "$TERM $cmd"
    elif [[ $cmd[1]:t == "svn" ]]; then
        title "$cmd[1,2]" "$TERM $cmd"
    elif [[ $cmd[1]:t == "ls" ]] || [[ $cmd[1]:t == "ll" ]] ; then
    else
        title $cmd[1]:t "$TERM $cmd[2,-1]"
    fi
}
 
#-----------------key bindings to fix keyboard---------------------------
#bindkey "\M-v" "\`xclip -o\`\M-\C-e\""
# create a zkbd compatible hash;
# to add other keys to this hash, see: man 5 terminfo
autoload -U zkbd
source ~/.zkbd/$TERM-$VENDOR-$OSTYPE
bindkey -e #use emacs style keybindings :(
#typeset -A key #define an array
#
#key[Home]=${terminfo[khome]}
#key[End]=${terminfo[kend]}
#key[Insert]=${terminfo[kich1]}
#key[Delete]=${terminfo[kdch1]}
#key[Up]=${terminfo[kcuu1]}
#key[Down]=${terminfo[kcud1]}
#key[Left]=${terminfo[kcub1]}
#key[Right]=${terminfo[kcuf1]}
#key[PageUp]=${terminfo[kpp]}
#key[PageDown]=${terminfo[knp]}
 
# setup key accordingly
[[ -n "${key[Home]}" ]] && bindkey "${key[Home]}" beginning-of-line
[[ -n "${key[End]}" ]] && bindkey "${key[End]}" end-of-line
[[ -n "${key[Insert]}" ]] && bindkey "${key[Insert]}" overwrite-mode
[[ -n "${key[Delete]}" ]] && bindkey "${key[Delete]}" delete-char
[[ -n "${key[Up]}" ]] && bindkey "${key[Up]}" up-line-or-history
[[ -n "${key[Down]}" ]] && bindkey "${key[Down]}" down-line-or-history
[[ -n "${key[Left]}" ]] && bindkey "${key[Left]}" backward-char
[[ -n "${key[Right]}" ]] && bindkey "${key[Right]}" forward-char
 
bindkey "" history-beginning-search-backward
bindkey "" history-beginning-search-forward
 
#-----------------user defined widgets & binds-----------------------
#from linuxtoy.org:
# pressing TAB in an empty command makes a cd command with completion list
dumb-cd(){
    if [[ -n $BUFFER ]] ; then # 如果该行有内容
        zle expand-or-complete # 执行 TAB 原来的功能
    else # 如果没有
        BUFFER="cd " # 填入 cd(空格)
        zle end-of-line # 这时光标在行首,移动到行末
        zle expand-or-complete # 执行 TAB 原来的功能
    fi
}
zle -N dumb-cd
bindkey "\t" dumb-cd #将上面的功能绑定到 TAB 键
 
#拼音补全
function _pinyin() { reply=($($HOME/bin/chsdir 0 $*)) }
 
#c-z to continue as well
bindkey -s "" "fg\n"
#----------------------distro specific stuff---------------------------
#if `cat /etc/issue |grep Arch >/dev/null`; then
# function command_not_found_handler() {
# echo "Man, you really need some coffee. \nA clear-headed one would not type things like \"$1\"."|cowsay -f small -W 50
# if grep Arch /etc/issue >/dev/null; then
# echo
# pacfile /bin/$1$|awk '{split($1,a,"/");print a[1] "/\033[31m" a[2] "\033[m\t\t\t/" $2}'
# fi
# return 0
# }
#fi
#----------------------variables---------------------------------------
export PATH=$PATH:$HOME/bin:$HOME/.gem/ruby/1.8/bin
export EDITOR=vim
export VISUAL=vim
 
#MOST like colored man pages
export LESS_TERMCAP_md=$'\E[1;31m' #bold1
export LESS_TERMCAP_mb=$'\E[1;31m'
export LESS_TERMCAP_me=$'\E[m'
export LESS_TERMCAP_so=$'\E[01;44;33m' #search highlight
export LESS_TERMCAP_se=$'\E[m'
export LESS_TERMCAP_us=$'\E[1;2;32m' #bold2
export LESS_TERMCAP_ue=$'\E[m'
export LESS="-M -i -R --shift 5"
export LESSCHARSET=utf-8
#export LESSOPEN="|lesspipe.sh %s" #lesspipe
 
#for ConTeX
#source $HOME/.context_env /home/roylez/soft/ConTeXt/tex
 
#for gnuplot, avoid locate!!!
#export GDFONTPATH=$(dirname `locate DejaVuSans.ttf | tail -1`)
[[ -n $DISPLAY ]] && export GDFONTPATH=/usr/share/fonts/TTF
 
#for intel fortran compiler
#source $HOME/soft/intel/ifort/bin/ifortvars.sh
 
#for slrn
#export NNTPSERVER=news.newsfan.net