-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.liuzheng_bashrc
495 lines (409 loc) · 12 KB
/
.liuzheng_bashrc
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
PATH=$PATH:$HOME
export PS1='\033[1;32;48m[\033[1;31;48m\u\033[1;31;48m@\033[4;32;48m\h\033[0;32;48m:\033[1;32;40m\w\033[0;32;48m`B=$(git branch 2>/dev/null | sed -e "/^ /d" -e "s/* \(.*\)/\1/"); if [ "$B" != "" ]; then S="git"; elif [ -e .bzr ]; then S=bzr; elif [ -e .hg ]; then S="hg";B="$(hg branch)"; elif [ -e .svn ]; then S="svn"; else S=""; fi; if [ "$S" != "" ]; then if [ "$B" != "" ]; then M=$S:$B; else M=$S; fi; fi; [[ "$M" != "" ]] && echo -n -e "\[\e[33;40m\]($M)\[\033[01;32m\]\[\e[00m\]"`\033[1;32;48m] \033[1;32;40m>>\d//\t<<\033[0;32;49m \n\[\033[1;31;48m\]\$ \[\e[0m\]'
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
HISTSIZE=10000
HISTFILESIZE=20000
#===================alias=======================
# ls
alias ll='ls -l'
alias la='ls -Al'
alias ls='ls -hF --color'
alias lx='ls -lXB'
alias lk='ls -lSr'
alias lc='ls -lcr'
alias lu='ls -lur'
alias lr='ls -lR'
alias lt='ls -ltr'
alias lm='ls -al |more'
alias dit="docker run --rm -v /var/run/docker.sock:/var/run/docker.sock nate/dockviz images -t"
# hand wrong
alias vf='cd'
alias xs='cd'
alias ks='ls'
alias kk='ll'
alias moew='more'
# df
alias dfh='df -h'
# make
alias mk="make"
alias mki="make install"
# clc
alias clc="clear"
alias lcl="clear"
# cd
alias c="cd"
# git
alias gitc='git clone'
alias gpom='git push origin master'
alias gitp='git pull'
alias gita='git add'
alias gitA='git add -A'
alias gitm='git commit'
alias gitM='git commit -m'
alias gits='git push'
# grep
alias grep='grep --color'
alias egrep='egrep --color'
alias fgrep='fgrep --color'
#===================alias end===================
export LANG=zh_CN.UTF-8
export LC_NUMERIC=en_US.UTF-8
export LC_TIME=en_US.UTF-8
export LC_COLLATE=en_US.UTF-8
export LC_MONETARY=en_US.UTF-8
export LC_MESSAGES=en_US.UTF-8
export LC_PAPER=en_US.UTF-8
export LC_NAME=en_US.UTF-8
export LC_ADDRESS=en_US.UTF-8
export LC_TELEPHONE=en_US.UTF-8
export LC_MEASUREMENT=en_US.UTF-8
export LC_IDENTIFICATION=en_US.UTF-8
export LC_CTYPE=zh_CN.UTF-8
export LC_ALL="C"
export LANGUAGE=zh_CN.UTF-8
#====================color======================
red=$'\e[0;31m'
RED=$'\e[1;31m'
blue=$'\e[0;34m'
BLUE=$'\e[1;34m'
cyan=$'\e[0;36m'
CYAN=$'\e[1;36m'
NC=$'\e[0m'
normal=$'\e[m'
white=$'\e[0;37m'
WHITE=$'\e[1;37m'
magenta=$'\e[0;35m'
MAGENTA=$'\e[1;35m'
yellow=$'\e[0;33m'
YELLOW=$'\e[1;33m'
green=$'\e[0;32m'
GREEN=$'\e[1;32m'
black=$'\e[0;30m'
BLACK=$'\e[1;30m'
#==================color end====================
#===================function====================
# pathogen rm bundle
function vimrm()
{
rm -rf $1
git rm -r $1
}
# pathogen git add
function vimgit()
{
if [ -z $1 ];then
echo 'Usage: vimgit GITPATH, examp: vimgit https://github.com/vim-scripts/The-NERD-tree.git'
else
name=`echo $1|sed 's/.*\/\(.*\)\.git/\1/g'`
git submodule add $1 .vim/bundle/$name
fi
}
# pathogen git pull all
function vimupdate()
{
git submodule foreach 'git checkout master && git pull'
}
# get ip
function myip()
{
MY_IP=$(/sbin/ifconfig eth0 | awk '/inet/ { print $2 } ' | sed -e s/addr://)
MY_ISP=$(/sbin/ifconfig eth0 | awk '/P-t-P/ { print $3 } ' | sed -e s/P-t-P://)
}
# find text in the file
function ffi()
{
grep -D skip -nRe "$1" .
}
# get local computer info
function ii()
{
echo -e "You are logged on ${RED}$HOST"
echo -e "Additionnal information:$NC " ; uname -a
echo -e "${RED}Users logged on:$NC " ; w -h
echo -e "${RED}Current date :$NC " ; cal
echo -e "${RED}Machine stats :$NC " ; uptime
echo -e "${RED}Memory stats :$NC " ; free
myip 2>&- ;
echo -e "${RED}Local IP Address :$NC" ; echo ${MY_IP:-"Not connected"}
echo -e "${RED}ISP Address :$NC" ; echo ${MY_ISP:-"Not connected"}
echo
}
# find file name
function ff() { find . -type f -iname '*'$*'*' -ls ; }
function psshc(){
pssh -h ~/config/server.list -l root -P $1
}
function psshp(){
pscp -h ~/config/server.list -l root $1 $2
}
function psshg(){
prsync -r -h ~/config/server.list -l $1 $2
}
# gitsubupdate
function gitsubupdate()
{
git commit | grep 'modified' | grep 'untracked' | awk '{print "rm -fr " $2 "&& rm -fr ./git/submodule/"$2}' | sh
git submodule init
git submodule update
#fn=`git commit | grep 'modified:' | sed -e 's/.*: *\(.*\) .* .*/\1/g'`
#for name in $fn
# do
# rm -rf $name
# rm -rf './git/submodule/'$name
# git submodule init
# git submodule update
# done
}
function gb2utf()
{
iconv -f gb2312 -t utf-8 $1>$1+f && mv $1+f $1
}
# swap
function addswap()
{
swapoff /home/swap
dd if=/dev/zero of=/home/swap bs=1024 count=$1
mkswap /home/swap
swapon /home/swap
}
# find same file
function fsamef()
{
find . \! -type d -exec md5sum '{}' ';' | sort | uniq -D -w 33
}
# salt function
function saltall()
{
sudo salt '*' $1 $2 $3
}
function saltpingall()
{
saltall test.ping
}
function saltcpfile()
{
saltall cp.get_file salt://$1 $2
}
function saltcmd()
{
p=""
for i in $*
do
p=$p" "$i
done
echo $p
sudo salt '*' cmd.run " $p "
}
function xelatexin()
{
cp ~/config/simple/xelatex/* .
case $1 in
book)
rm *article*
;;
article)
rm *book*
;;
*)
rm *book*
;;
esac
}
function sj() { date +%T ; }
function rq() { date +%F ; }
function SJ() { date +%F-%T ; }
function addblog() { rake post title="$1" ; }
#==================function end=================
#=================complete======================
#
# 按情况补全, complete命令 - BASH-2.04及其后续版本
# 大部分摘自bash 2.05文档
# 和Ian McDonalds的'Bash completion'软件包(http://www.caliban.org/bash/index.shtml#completion)
# 某些特征可能需要使用bash-2.05a
#
#=========================================================================
if [ "${BASH_VERSION%.*}" \< "2.05" ]; then
echo "You will need to upgrade to version 2.05 for programmable completion"
return
fi
shopt -s extglob # 必须的
set +o nounset # 否则某些自动补全将会失败
complete -A hostname rsh rcp telnet rlogin r ftp ping disk
complete -A export printenv
complete -A variable export local readonly unset
complete -A enabled builtin
complete -A alias alias unalias
complete -A function function
complete -A user su mail finger
complete -A helptopic help # 通常与内建命令一样
complete -A shopt shopt
complete -A stopped -P '%' bg
complete -A job -P '%' fg jobs disown
complete -A directory mkdir rmdir
complete -A directory -o default cd
# 压缩
complete -f -o default -X '*.+(zip|ZIP)' zip
complete -f -o default -X '!*.+(zip|ZIP)' unzip
complete -f -o default -X '*.+(z|Z)' compress
complete -f -o default -X '!*.+(z|Z)' uncompress
complete -f -o default -X '*.+(gz|GZ)' gzip
complete -f -o default -X '!*.+(gz|GZ)' gunzip
complete -f -o default -X '*.+(bz2|BZ2)' bzip2
complete -f -o default -X '!*.+(bz2|BZ2)' bunzip2
# Postscript,pdf,dvi.....(译者: 打印格式相关)
complete -f -o default -X '!*.ps' gs ghostview ps2pdf ps2ascii
complete -f -o default -X '!*.dvi' dvips dvipdf xdvi dviselect dvitype
complete -f -o default -X '!*.pdf' acroread pdf2ps
complete -f -o default -X '!*.+(pdf|ps)' gv
complete -f -o default -X '!*.texi*' makeinfo texi2dvi texi2html texi2pdf
complete -f -o default -X '!*.tex' tex latex slitex
complete -f -o default -X '!*.lyx' lyx
complete -f -o default -X '!*.+(htm*|HTM*)' lynx html2ps
# 多媒体
complete -f -o default -X '!*.+(jp*g|gif|xpm|png|bmp)' xv gimp
complete -f -o default -X '!*.+(mp3|MP3)' mpg123 mpg321
complete -f -o default -X '!*.+(ogg|OGG)' ogg123
complete -f -o default -X '!*.pl' perl perl5
# 这是一个'通用的'补全函数 - 当命令具有一个所谓的"长选项"模式it works when commands have
# 的时候, 它就会工作, 比如: 'ls --all' 代替 'ls -a'
_get_longopts ()
{
$1 --help | sed -e '/--/!d' -e 's/.*--\([^[:space:].,]*\).*/--\1/'| \
grep ^"$2" |sort -u ;
}
_longopts_func ()
{
case "${2:-*}" in
-*) ;;
*) return ;;
esac
case "$1" in
\~*) eval cmd="$1" ;;
*) cmd="$1" ;;
esac
COMPREPLY=( $(_get_longopts ${1} ${2} ) )
}
complete -o default -F _longopts_func configure bash
complete -o default -F _longopts_func wget id info a2ps ls recode
_make_targets ()
{
local mdef makef gcmd cur prev i
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
# 如果之前的参数为-f, 那就返回可能的补全文件名.
# 我们可以让它更智能一些, 并且返回匹配的
# `makefile Makefile *.mk', 不管存在与否
case "$prev" in
-*f) COMPREPLY=( $(compgen -f $cur ) ); return 0;;
esac
# 如果我们需要一个选项, 那就返回可能的posix选项
case "$cur" in
-) COMPREPLY=(-e -f -i -k -n -p -q -r -S -s -t); return 0;;
esac
# 前尝试`makefile'再尝试`Makefile'
if [ -f makefile ]; then
mdef=makefile
elif [ -f Makefile ]; then
mdef=Makefile
else
mdef=*.mk # 局部约定
fi
# 在我们扫描目标文件之前, 察看makefile文件名是否
# 使用-f指定
for (( i=0; i < ${#COMP_WORDS[@]}; i++ )); do
if [[ ${COMP_WORDS[i]} == -*f ]]; then
eval makef=${COMP_WORDS[i+1]} # eval for tilde expansion(波浪号扩展)
break
fi
done
[ -z "$makef" ] && makef=$mdef
# 如果我们有特别偏爱的补全单词,
# 那么可以限制的补全这个单词
if [ -n "$2" ]; then gcmd='grep "^$2"' ; else gcmd=cat ; fi
# 如果我们不想使用*.mk, 我们可以使用
# 或者使用test -f $makef或者使用输入重定向
COMPREPLY=( $(cat $makef 2>/dev/null | awk 'BEGIN {FS=":"} /^[^.# ][^=]*:/ {print $1}' | tr -s ' ' '\012' | sort -u | eval $gcmd ) )
}
complete -F _make_targets -X '+($*|*.[cho])' make gmake pmake
# cvs(1) 补全
_cvs ()
{
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
if [ $COMP_CWORD -eq 1 ] || [ "${prev:0:1}" = "-" ]; then
COMPREPLY=( $( compgen -W 'add admin checkout commit diff \
export history import log rdiff release remove rtag status \
tag update' $cur ))
else
COMPREPLY=( $( compgen -f $cur ))
fi
return 0
}
complete -F _cvs cvs
_killall ()
{
local cur prev
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
# 获得进程列表(第一个sed表达式处理
# swap out出去的进程, 第二个
# 获得进程的basename)
COMPREPLY=( $( /usr/bin/ps -u $USER -o comm | \
sed -e '1,1d' -e 's#[]\[]##g' -e 's#^.*/##'| \
awk '{if ($0 ~ /^'$cur'/) print $0}' ))
return 0
}
complete -F _killall killall killps
# 一个元命令补全函数, 用于sudo(8)这种命令,
# 需要先对这个命令进行补全, 然后需要按照这个命令自己的补全定义进行补全
# - 当前并不是非常可靠(比如 mount和umount命令
# 就不能很好的工作), 但还是很有用的 - 作者, Ian McDonald, 我修改了一下.
_my_command()
{
local cur func cline cspec
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
if [ $COMP_CWORD = 1 ]; then
COMPREPLY=( $( compgen -c $cur ) )
elif complete -p ${COMP_WORDS[1]} &>/dev/null; then
cspec=$( complete -p ${COMP_WORDS[1]} )
if [ "${cspec%%-F *}" != "${cspec}" ]; then
# complete -F <function>
#
# COMP_CWORD和COMP_WORDS()不是只读的,
# 所以我们可以在传递到补全例程之前,
# 设置它们
# 设置当前的标志号减1
COMP_CWORD=$(( $COMP_CWORD - 1 ))
# 获得函数名
func=${cspec#*-F }
func=${func%% *}
# 获得去掉第一个命令后的命令行
cline="${COMP_LINE#$1 }"
# 分离当前命令, 传递给数组
COMP_WORDS=( $cline )
$func $cline
elif [ "${cspec#*-[abcdefgjkvu]}" != "" ]; then
# complete -[abcdefgjkvu]
#func=$( echo $cspec | sed -e 's/^.*\(-[abcdefgjkvu]\).*$/\1/' )
func=$( echo $cspec | sed -e 's/^complete//' -e 's/[^ ]*$//' )
COMPREPLY=( $( eval compgen $func $cur ) )
elif [ "${cspec#*-A}" != "$cspec" ]; then
# complete -A <type>
func=${cspec#*-A }
func=${func%% *}
COMPREPLY=( $( compgen -A $func $cur ) )
fi
else
COMPREPLY=( $( compgen -f $cur ) )
fi
}
complete -o default -F _my_command nohup exec eval trace truss strace sotruss gdb
complete -o default -F _my_command command type which man nice
export EDITOR=/usr/bin/vim
#============= git complete ===================
. ~/config/git-completion.bash