-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbash.bashrc
executable file
·143 lines (117 loc) · 3.18 KB
/
bash.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
#!/bin/bash
#
#
#Remeber to add below line in ~/.bashrc
# source ~/srcutils/bash.bashrc
export EDITOR=vi
export PATH=~/srcutils/bin/:$PATH
export GTAGSFORCECPP=""
#history config
HISTCONTROL=erasedups:ignorespace
HISTSIZE=9000
HISTFILESIZE=9000
#ls alias
alias ll='ls -clth'
alias ls='ls --group-directories-first --color=never'
alias cls='ack-grep -f --asm --cc --cpp'
alias jls='ack-grep -f --java'
#grep alias
alias grep='grep --color=never'
alias fgrep='fgrep --color=never'
alias egrep='egrep --color=never'
alias man='LC_MESSAGES=en_US.UTF-8 man'
alias svnst='svn status|grep "\." | grep -v ".obj"'
function fname()
{
find . -iname "*$@*"
}
function mkgrep()
{
find . -name .repo -prune -o -name .git -prune -o -type f \( -name '*.mk' -o -name Makefile -o -name Makefile.am \) -print0 | xargs -0 grep --color -n "$@"
}
function kgrep()
{
find . -name .repo -prune -o -name .git -prune -o -type f \( -name 'Kconfig*' -o -name Makefile -o -name Kbuild \) -print0 | xargs -0 grep --color -n "$@"
}
function jgrep()
{
find . -name .repo -prune -o -name .git -prune -o -type f -name "*\.java" -print0 | xargs -0 grep --color -n "$@"
}
function sgrep()
{
find . -name .repo -prune -o -name .git -prune -o -type f -iname "*\.S" -print0 | xargs -0 grep --color -n "$@"
}
function cgrep()
{
find . -name .repo -prune -o -name .git -prune -o -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.inl' -o -iname "*\.S" \) -print0 | xargs -0 grep --color -n "$@"
}
function resgrep()
{
for dir in `find . -name .repo -prune -o -name .git -prune -o -name res -type d`; do find $dir -type f -name '*\.xml' -print0 | xargs -0 grep --color -n "$@"; done;
}
MY_CD_FILELIST="/data/godir_filelist"
function mycd()
{
local lastarg=${!#}
if [[ ! -d $lastarg ]]
then
return
fi
if [[ ! -f $MY_CD_FILELIST ]]
then
touch $MY_CD_FILELIST
fi
local mydir=$(readlink -f $lastarg)
cd $*
if grep -q -x -F "$mydir" $MY_CD_FILELIST
then
return
fi
local maxnum=200
local halfnum=$(($maxnum/2))
local filenum=$(wc -l $MY_CD_FILELIST | cut -d' ' -f1)
if [[ $filenum -ge $maxnum ]]
then
tail -$halfnum $MY_CD_FILELIST > /tmp/tmp_filelist
mv /tmp/tmp_filelist $MY_CD_FILELIST
fi
echo $mydir >> $MY_CD_FILELIST
}
alias cd='mycd'
function godir ()
{
if [[ -z "$1" ]]; then
echo "Usage: godir <regex>"
return
fi
local lines
lines=($(grep "$1" $MY_CD_FILELIST | sort | uniq))
if [[ ${#lines[@]} = 0 ]]; then
echo "Not found"
return
fi
local pathname
local choice
if [[ ${#lines[@]} > 1 ]]; then
while [[ -z "$pathname" ]]; do
local index=1
local line
for line in ${lines[@]}; do
printf "%6s %s\n" "[$index]" $line
index=$(($index + 1))
done
echo
echo -n "Select one: "
unset choice
read choice
if [[ $choice -gt ${#lines[@]} || $choice -lt 1 ]]; then
echo "Invalid choice"
continue
fi
pathname=${lines[$(($choice-1))]}
done
else
pathname=${lines[0]}
fi
cd $pathname
}