forked from baohaojun/system-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc-public-bash
executable file
·224 lines (197 loc) · 5.28 KB
/
.bashrc-public-bash
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
#!/bin/bash
qcd()
{
local branch=$(git symbolic-ref HEAD)
branch=${branch#refs/heads/}
cd .git/patches/$branch
}
lcd()
{
if test $# != 1; then
return 1
elif test "$1" = -; then
cd_ok -
return 0
elif test "$1" = .beagrep; then
cd_beagrep;
return 0;
fi
if test "${1:0:3}" = ' \\'; then # copied from mantis webpages, will contain space at start and end
set -- "${1# }"
set -- "${1% }"
fi
if [[ "$1" =~ ^\\\\|^//|^smb://|^file:///[0-9]+\.|/smb/ && `uname` = Linux ]]; then
chmod 600 ~/.smb/*
if ! mount | grep -q '^smbnetfs on'; then
if smbnetfs -o allow_root ~/smb 2>&1|grep -v "mountpoint is not empty\|'nonempty' mount option\|gnome-keyring is not available"|grep -q . ; then
sudo umount -l ~/smb
smbnetfs -o allow_root ~/smb 2>&1|grep -v "mountpoint is not empty\|'nonempty' mount option\|gnome-keyring is not available"
fi
fi
builtin cd ~/smb/"$(ip-or-name "$1")"
return 0
fi
local ori=$1
local start=$PWD
local looking=$PWD
local x=0
while ! test -e "$1" >/dev/null || { [[ "$looking" =~ ^$HOME/smb(/[^/]+)?$ ]] && test "$looking" != "$start"; }; do # [[..]] because test -e not work in smbnetfs top levels
set -- ../"$1";
looking=`dirname "$looking"`
test "$looking" = / && break
if test -e "$looking"/"$ori"; then
if test -d "$looking"/"$ori"; then
builtin cd "$looking"/"$ori"
else
builtin cd "$(dirname "$looking"/"$ori")"
fi
return $?
fi
done
if ! test -e "$1" >/dev/null; then
_ucd $ori
return $?
fi
link=$1
if test -f "$link" && echo "${link##*.}"|grep -i '^lnk$' -q; then
link=`readshortcut "$link"`
fi
if test -d "$link"; then
if test "$link" = "`pwd`"; then
return 1;
fi
builtin cd "$link"
return $?
elif test -L "$link" -a -f "$link"; then
builtin cd "$(dirname "$(readlink -f "$link")")"
return $?
else
builtin cd "$(dirname "$link")"
return $?
fi
}
_ucd() #we go to upper dir which match the $1, for ex, cd 'ho' in /home/bhj will go to /home,
{
local x=0
dir=`dirname "$(pwd)"`
dir_basename=`basename "$dir"`
while ! echo $dir_basename|grep -e $1 -i -q && ((x++ < 10)); do
dir=`dirname "$dir"`
dir_basename=`basename "$dir"`
if test x"$dir" = x/; then
break
fi
done
if test x"$dir" = x/; then #obviously, we very not likely want to go to / with this complex setup
return 1;
fi
builtin cd "$dir"
return $?
}
svn-info-clip()
{
svn info "$1" |grep '^URL:'|sed -e 's/^URL: //; s/^https/http/'|tr -d '\r\n' | putclip
}
alias for-code-reading='for-code-reading -i -v'
function hir() {
if test $# = 0; then
history -r
backup_bash_history
echo "~/.bash_history.bak has $(wc -l ~/.bash_history.bak|pn 1) lines"
cat ~/.where.bak >> ~/.where
else
command hil "$@"
fi
}
function _select_cd() {
local IFS=$'\n'
local dirs=(
"$@"
)
if test ${#dirs[@]} = 0; then
echo 'Error: no such file or directory'
return 1
elif test ${#dirs[@]} = 1; then
builtin cd ${dirs[0]}
else
NUM=`my-select "${dirs[@]}"`
((NUM--))
builtin cd "${dirs[$NUM]}"
fi
}
function tcd() {
local IFS=$'\n'
_select_cd $(
export LOOKUP_NON_EXIST_FILES=false
lookup-file $(today "$@" | perl -npe 's/(.*)-.*/$1/')
lookup-file `today-- "$@"`
) $(
export LOOKUP_NON_EXIST_FILES=false
pcd ~/today && {
lookup-file $(today "$@" | perl -npe 's/(.*)-.*/$1/')
lookup-file `today-- "$@"`;
}
)
}
function mcd() {
local IFS=$'\n'
_select_cd $(lookup-file "$@")
}
alias hil=hir
cd_record()
{
local ret=$?
if test $ret -ne 0; then
export PROMPT_RET="Ret: $ret @ $(date +%H:%M:%S) "
else
export PROMPT_RET=
fi
history -a
if test -e ~/.reset-env; then
. ~/.reset-env
rm -f ~/.reset-env
fi
if test "$ANDROID_SERIAL" && ! echo "$RECURSIVE_SHELL" | grep -q -e "adb-$ANDROID_SERIAL\."; then
RECURSIVE_SHELL=$(echo "$RECURSIVE_SHELL" | perl -npe 's/adb-\S+\s*//g;')
if test "$RECURSIVE_SHELL"; then
export RECURSIVE_SHELL="$RECURSIVE_SHELL: ""adb-$ANDROID_SERIAL."
else
export RECURSIVE_SHELL="adb-$ANDROID_SERIAL."
fi
fi
if test "$BHJ_PWD" = "$PWD"; then
return $ret
fi
BHJ_PWD=$PWD
(
if test "$LC_ALL" != C -a "$has_python3"; then
where;
fi&
)
return $ret
}
start_recursive_shell()
{
(
export RECURSIVE_SHELL='[01;32mRecursive[01;31m:[01;32m'"$@"'[0m '
bash
)
}
adb()
{
my-adb "$@"
}
export -f start_recursive_shell
alias start-recursive-shell=start_recursive_shell
if which python3 >/dev/null 2>&1; then
has_python3=true
else
has_python3=
fi
export PROMPT_COMMAND="cd_record"
if test -n "$has_python3"; then
alias cd=cd_bhj
fi
alias cow='cp --reflink=always -a'
shopt -s nocaseglob
shopt -s histappend