-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.zshrc
595 lines (514 loc) · 20.4 KB
/
.zshrc
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
#!/bin/zsh
# vim:fdm=marker
# 预配置 {{{
# 如果不是交互shell就直接结束 (unix power tool, 2.11)
if [[ "$-" != *i* ]]; then return 0; fi
# 为兼容旧版本定义 is-at-least 函数
function is-at-least {
local IFS=".-" min_cnt=0 ver_cnt=0 part min_ver version
min_ver=(${=1})
version=(${=2:-$ZSH_VERSION} 0)
while (( $min_cnt <= ${#min_ver} )); do
while [[ "$part" != <-> ]]; do
(( ++ver_cnt > ${#version} )) && return 0
part=${version[ver_cnt]##*[^0-9]}
done
while true; do
(( ++min_cnt > ${#min_ver} )) && return 0
[[ ${min_ver[min_cnt]} = <-> ]] && break
done
(( part > min_ver[min_cnt] )) && return 0
(( part < min_ver[min_cnt] )) && return 1
part=''
done
}
export SHELL=`which zsh`
# 定义颜色 {{{
if [[ ("$TERM" == *256color || "$TERM" == screen*) && -f $HOME/.lscolor256 ]]; then
#use prefefined colors
eval $(dircolors -b $HOME/.lscolor256)
else
[[ -f $HOME/.lscolor ]] && eval $(dircolors -b $HOME/.lscolor)
fi
#color defined for prompts and etc
autoload colors
[[ $terminfo[colors] -ge 8 ]] && colors
pR="%{$reset_color%}%u%b" pB="%B" pU="%U"
for i in red green blue yellow magenta cyan white black; {eval pfg_$i="%{$fg[$i]%}" pbg_$i="%{$bg[$i]%}"}
#}}}
#}}}
# 设置参数 {{{
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 auto_continue #automatically send SIGCON to disowned jobs
setopt extended_glob # so that patterns like ^() *~() ()# can be used
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 no_hist_beep # don not beep on history expansion errors
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 hist_ignore_space # do not remember commands starting with space
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 # comments in history
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
setopt prompt_subst # prompt more dynamic, allow function in prompt
setopt nonomatch
#remove / and . from WORDCHARS to allow alt-backspace to delete word
WORDCHARS='*?_-[]~=&;!#$%^(){}<>'
#report to me when people login/logout
watch=(notme)
#replace the default beep with a message
#ZBEEP="\e[?5h\e[?5l" # visual beep
#is-at-least 4.3.0 &&
# 自动加载自定义函数
fpath=($HOME/.zfunctions $fpath)
# 需要设置了extended_glob才能glob到所有的函数,为了补全能用,又需要放在compinit前面
autoload -U ${fpath[1]}/*(:t)
# }}}
# 命令补全参数{{{
# zsytle ':completion:*:completer:context or command:argument:tag'
zmodload -i zsh/complist # for menu-list completion
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 _oldlist _expand _force_rehash _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[33m == \e[1;7;36m %d \e[m\e[33m ==\e[m'
zstyle ':completion:*:messages' format $'\e[33m == \e[1;7;36m %d \e[m\e[0;33m ==\e[m'
zstyle ':completion:*:warnings' format $'\e[33m == \e[1;7;31m No Matches Found \e[m\e[0;33m ==\e[m'
zstyle ':completion:*:corrections' format $'\e[33m == \e[1;7;37m %d (errors: %e) \e[m\e[0;33m ==\e[m'
#autoload -U compinit
autoload -Uz compinit
compinit
#force rehash when command not found
# http://zshwiki.org/home/examples/compsys/general
_force_rehash() {
(( CURRENT == 1 )) && rehash
return 1 # Because we did not really complete anything
}
# }}}
# 自定义函数 {{{
# 普通自定义函数 {{{
#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 using atd
alarm() {
echo "msg ${argv[2,-1]} && aplay -q ~/.sounds/MACSound/System\ Notifi.wav" | at now + $1 min
}
#calculator
calc() { awk "BEGIN{ print $* }" ; }
#check if a binary exists in path
bin-exist() {[[ -x `whence -cp $1 2>/dev/null` ]]}
#recalculate track db gain with mp3gain
(bin-exist mp3gain) && id3gain() { find $* -type f -iregex ".*\(mp3\|ogg\|wma\)" -exec mp3gain -r -s i {} \; }
#ccze for log viewing
(bin-exist ccze) && lless() { tac $* |ccze -A |less }
#man page to pdf
(bin-exist ps2pdf) && man2pdf() { man -t ${1:?Specify man as arg} | ps2pdf -dCompatibility=1.3 - - > ${1}.pdf; }
# }}}
#{{{ functions to set prompt pwd color
__PROMPT_PWD="$pfg_magenta%~$pR"
#change PWD color
pwd_color_chpwd() { [ $PWD = $OLDPWD ] || __PROMPT_PWD="$pU$pfg_cyan%~$pR" }
#change back before next command
pwd_color_preexec() { __PROMPT_PWD="$pfg_magenta%~$pR" }
#}}}
#{{{functions to display git branch in prompt
get_git_status() {
unset __CURRENT_GIT_BRANCH
unset __CURRENT_GIT_BRANCH_STATUS
unset __CURRENT_GIT_BRANCH_IS_DIRTY
# do not track git branch info in ~
[[ "$PWD" = "$HOME" ]] && return
local dir=$(git rev-parse --git-dir 2>/dev/null)
[[ "${dir:h}" = "$HOME" ]] && return
local st="$(git status 2>/dev/null)"
if [[ -n "$st" ]]; then
local -a arr
arr=(${(f)st})
if [[ $arr[1] =~ 'Not currently on any branch.' ]]; then
__CURRENT_GIT_BRANCH='no-branch'
else
__CURRENT_GIT_BRANCH="${arr[1][(w)4]}";
fi
if [[ $arr[2] =~ 'Your branch is' ]]; then
if [[ $arr[2] =~ 'ahead' ]]; then
__CURRENT_GIT_BRANCH_STATUS='ahead'
elif [[ $arr[2] =~ 'diverged' ]]; then
__CURRENT_GIT_BRANCH_STATUS='diverged'
else
__CURRENT_GIT_BRANCH_STATUS='behind'
fi
fi
[[ ! $st =~ "nothing to commit" ]] && __CURRENT_GIT_BRANCH_IS_DIRTY='1'
fi
}
git_branch_precmd() { [[ "$(fc -l -1)" == *git* ]] && get_git_status }
git_branch_chpwd() { get_git_status }
#this one is to be used in prompt
get_prompt_git() {
if [[ -n $__CURRENT_GIT_BRANCH ]]; then
local s=$__CURRENT_GIT_BRANCH
case "$__CURRENT_GIT_BRANCH_STATUS" in
ahead) s+="+" ;;
diverged) s+="=" ;;
behind) s+="-" ;;
esac
[[ $__CURRENT_GIT_BRANCH_IS_DIRTY = '1' ]] && s+="*"
echo " $pfg_black$pbg_white$pB $s $pR"
fi
}
#}}}
#{{{-----------------functions to set gnu screen title----------------------
# active command as title in terminals
case $TERM in
xterm*|rxvt*)
function title() { print -nP "\e]0;$1\a" }
;;
screen*)
#only set screen title if it is in a local shell
if [ -n $STY ] && (screen -ls |grep $STY &>/dev/null); then
function title()
{
#modify screen title
print -nP "\ek$1\e\\"
#modify window title bar
#print -nPR $'\033]0;'$2$'\a'
}
elif [ -n $TMUX ]; then # actually in tmux !
function title() { print -nP "\e]2;$1\a" }
else
function title() {}
fi
;;
*)
function title() {}
;;
esac
#set screen title if not connected remotely
#if [ "$STY" != "" ]; then
screen_precmd() {
#a bell, urgent notification trigger
#echo -ne '\a'
#title "`print -Pn "%~" | sed "s:\([~/][^/]*\)/.*/:\1...:"`" "$TERM $PWD"
title "`print -Pn "%~" |sed "s:\([~/][^/]*\)/.*/:\1...:;s:\([^-]*-[^-]*\)-.*:\1:"`" "$TERM $PWD"
echo -ne '\033[?17;0;127c'
}
screen_preexec() {
local -a cmd; cmd=(${(z)1})
case $cmd[1]:t in
'ssh') title "@""`echo $cmd[2]|sed 's:.*@::'`" "$TERM $cmd";;
'sudo') title "#"$cmd[2]:t "$TERM $cmd[3,-1]";;
'for') title "()"$cmd[7] "$TERM $cmd";;
'svn'|'git') title "$cmd[1,2]" "$TERM $cmd";;
'ls'|'ll') ;;
*) title $cmd[1]:t "$TERM $cmd[2,-1]";;
esac
}
#}}}
#{{{-----------------define magic function arrays--------------------------
if ! (is-at-least 4.3); then
#the following solution should work on older version <4.3 of zsh.
#The "function" keyword is essential for it to work with the old zsh.
#NOTE these function fails dynamic screen title, not sure why
#CentOS stinks.
function precmd() {
screen_precmd
git_branch_precmd
}
function preexec() {
screen_preexec
pwd_color_preexec
}
function chpwd() {
pwd_color_chpwd
git_branch_chpwd
}
else
#this works with zsh 4.3.*, will remove the above ones when possible
typeset -ga preexec_functions precmd_functions chpwd_functions
precmd_functions+=screen_precmd
precmd_functions+=git_branch_precmd
preexec_functions+=screen_preexec
preexec_functions+=pwd_color_preexec
chpwd_functions+=pwd_color_chpwd
chpwd_functions+=git_branch_chpwd
fi
#}}}
# }}}
# 提示符 {{{
if [ "$SSH_TTY" = "" ]; then
local host="$pB$pfg_magenta%m$pR"
else
local host="$pB$pfg_red%m$pR"
fi
local user="$pB%(!:$pfg_red:$pfg_green)%n$pR" #different color for privileged sessions
local symbol="$pB%(!:$pfg_red# :$pfg_yellow> )$pR"
local job="%1(j,$pfg_red:$pfg_blue%j,)$pR"
PROMPT='$user$pfg_yellow@$pR$host$(get_prompt_git)$job$symbol'
PROMPT2="$PROMPT$pfg_cyan%_$pR $pB$pfg_black>$pR$pfg_green>$pB$pfg_green>$pR "
#NOTE **DO NOT** use double quote , it does not work
typeset -A altchar
set -A altchar ${(s..)terminfo[acsc]}
PR_SET_CHARSET="%{$terminfo[enacs]%}"
PR_SHIFT_IN="%{$terminfo[smacs]%}"
PR_SHIFT_OUT="%{$terminfo[rmacs]%}"
#PR_RSEP=$PR_SET_CHARSET$PR_SHIFT_IN${altchar[\`]:-|}$PR_SHIFT_OUT
RPROMPT='$__PROMPT_PWD'
# SPROMPT - the spelling prompt
SPROMPT="${pfg_yellow}zsh$pR: correct '$pfg_red$pB%R$pR' to '$pfg_green$pB%r$pR' ? ([${pfg_cyan}Y$pR]es/[${pfg_cyan}N$pR]o/[${pfg_cyan}E$pR]dit/[${pfg_cyan}A$pR]bort) "
#行编辑高亮模式 {{{
if (is-at-least 4.3); then
zle_highlight=(region:bg=magenta
special:bold,fg=magenta
default:bold
isearch:underline
)
fi
#}}}
# }}}
# 键盘定义及键绑定 {{{
#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
bindkey -e #use emacs style keybindings :(
typeset -A key #define an array
#if zkbd definition exists, use defined keys instead
if [[ -f ~/.zkbd/${TERM}-${DISPLAY:-$VENDOR-$OSTYPE} ]]; then
source ~/.zkbd/$TERM-${DISPLAY:-$VENDOR-$OSTYPE}
else
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]}
for k in ${(k)key} ; do
# $terminfo[] entries are weird in ncurses application mode...
[[ ${key[$k]} == $'\eO'* ]] && key[$k]=${key[$k]/O/[}
done
fi
# 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
bindkey -M viins "" history-beginning-search-backward
bindkey -M viins "" history-beginning-search-forward
bindkey '[1;5D' backward-word # C-left
bindkey '[1;5C' forward-word # C-right
autoload -U edit-command-line
zle -N edit-command-line
bindkey '\ee' edit-command-line
# }}}
# }}}
# 自定义widget {{{
#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 键
# colorize command as blue if found in path or defined.
TOKENS_FOLLOWED_BY_COMMANDS=('|' '||' ';' '&' '&&' 'sudo' 'do' 'time' 'strace')
recolor-cmd() {
region_highlight=()
colorize=true
start_pos=0
for arg in ${(z)BUFFER}; do
((start_pos+=${#BUFFER[$start_pos+1,-1]}-${#${BUFFER[$start_pos+1,-1]## #}}))
((end_pos=$start_pos+${#arg}))
if $colorize; then
colorize=false
res=$(LC_ALL=C builtin type $arg 2>/dev/null)
case $res in
*'reserved word'*) style="fg=magenta,bold";;
*'alias for'*) style="fg=cyan,bold";;
*'shell builtin'*) style="fg=yellow,bold";;
*'shell function'*) style='fg=green,bold';;
*"$arg is"*)
[[ $arg = 'sudo' ]] && style="fg=red,bold" || style="fg=blue,bold";;
*) style='none,bold';;
esac
region_highlight+=("$start_pos $end_pos $style")
fi
[[ ${${TOKENS_FOLLOWED_BY_COMMANDS[(r)${arg//|/\|}]}:+yes} = 'yes' ]] && colorize=true
start_pos=$end_pos
done
}
check-cmd-self-insert() { zle .self-insert && recolor-cmd }
check-cmd-backward-delete-char() { zle .backward-delete-char && recolor-cmd }
zle -N self-insert check-cmd-self-insert
zle -N backward-delete-char check-cmd-backward-delete-char
#拼音补全
function _pinyin() { reply=($($HOME/bin/chsdir 0 $*)) }
#c-z to continue as well
bindkey -s "" "fg\n"
# }}}
# 环境变量及其他参数 {{{
# 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
export PATH=$PATH:$HOME/bin
export EDITOR=vim
export VISUAL=vim
export SUDO_PROMPT=$'[\e[31;5msudo\e[m] password for \e[33;1m%p\e[m: '
#MOST like colored man pages
export PAGER=less
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 READNULLCMD=less
# In archlinux the pipe script is in PATH, how ever in debian it is not
(bin-exist src-hilite-lesspipe.sh) && export LESSOPEN="| src-hilite-lesspipe.sh %s"
[ -x /usr/share/source-highlight/src-hilite-lesspipe.sh ] && export LESSOPEN="| /usr/share/source-highlight/src-hilite-lesspipe.sh %s"
#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
# 主机特定的配置,前置的主要原因是有可能需要提前设置PATH等环境变量
# 例如在aix主机,需要把 /usr/linux/bin
# 置于PATH最前以便下面的配置所调用的命令是linux的版本
[[ -f $HOME/.zshrc.local ]] && source $HOME/.zshrc.local
# redefine command not found
(bin-exist cowsay) && (bin-exist fortune) && command_not_found_handler() { fortune -s| cowsay -W 70}
# }}}
# 命令别名 {{{
# alias and listing colors
alias -g A="|awk"
alias -g B='|sed -r "s:\x1B\[[0-9;]*[mK]::g"' # remove color, make things boring
alias -g C="|wc"
alias -g E="|sed"
alias -g G='|GREP_COLOR=$(echo 3$[$(date +%N)%6+1]'\'';1;7'\'') egrep -i --color=always'
alias -g H="|head -n $(($LINES-2))"
alias -g L="|less"
alias -g P="|column -t"
alias -g R="|tac"
alias -g S="|sort"
alias -g T="|tail -n $(($LINES-2))"
alias -g X="|xargs"
alias -g N="> /dev/null"
alias -g NF="./*(oc[1])" # last modified(inode time) file or directory
# tmux or screen ?
(bin-exist tmux) && alias s=tmux || alias s=screen
#file types
(bin-exist apvlv) && alias -s pdf=apvlv
alias -s ps=gv
for i in jpg png; alias -s $i=gqview
for i in avi rmvb wmv; alias -s $i=mplayer
for i in rar zip 7z lzma; alias -s $i="7z x"
#no correct for mkdir mv and cp
for i in mkdir mv cp; alias $i="nocorrect $i"
alias find='noglob find' # noglob for find
alias grep='grep -I --color=auto'
alias egrep='egrep -I --color=auto'
alias cal='cal -3m'
alias freeze='kill -STOP'
alias ls=$'ls -h --color=auto -X --time-style="+\e[33m[\e[32m%Y-%m-%d \e[35m%k:%M\e[33m]\e[m"'
alias vi='vim'
alias ll='ls -l'
alias df='df -Th'
alias du='du -h'
#show directories size
alias dud='du -s *(/)'
#date for US and CN
alias adate='for i in US/Eastern Australia/{Brisbane,Sydney} Asia/{Hong_Kong,Singapore} Europe/Paris; do printf %-22s "$i:";TZ=$i date +"%m-%d %a %H:%M";done'
#bloomberg radio
alias bloomberg='mplayer mms://media2.bloomberg.com/wbbr_sirus.asf'
alias pyprof='python -m cProfile'
alias python='nice python'
alias info='info --vi-keys'
alias ri='ri -f ansi'
alias history='history 1' #zsh specific
alias zhcon='zhcon --utf8'
alias vless="/usr/share/vim/vim72/macros/less.sh"
del() {mv -vif -- $* ~/.Trash}
alias m='mutt'
alias port='netstat -ntlp' #opening ports
#Terminal - Harder, Faster, Stronger SSH clients
#alias ssh="ssh -4 -C -c blowfish-cbc"
alias e264='mencoder -vf harddup -ovc x264 -x264encopts crf=22:subme=5:frameref=2:8x8dct:bframes=3:weight_b -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 gfw="ssh -o ServerAliveInterval=60 -CNfg -D 7777 -l roy lychee &>/dev/null &"
alias gfw="ssh -o ServerAliveInterval=60 -Cg -D 7070"
(bin-exist pal) && alias pal="pal -r 0-7 --color"
[ -d /usr/share/man/zh_CN ] && alias cman="MANPATH=/usr/share/man/zh_CN man"
alias tnethack='telnet nethack.alt.org'
alias tslashem='telnet slashem.crash-override.net'
#}}}
typeset -U PATH