-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbashrc.auto.export
81 lines (65 loc) · 1.21 KB
/
bashrc.auto.export
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
#######
# ½øÈëuosĿ¼ʱ×Ô¶¯¼ì²âexport.sh
#######
is_set=false
PS1_bak="$PS1"
#isAbsDir()
#{
# ch=`expr substr $1 1 1`
# [ "$ch" = "/" -o "$ch" = "~" ] && return 0
# return 1
#}
checkExport()
{
if [ -f $1/export.sh ]
then
if $is_set && [ "$UOS_BASE" = "$1" ]
then
return 0
fi
command cd $1
. export.sh
PS1=`echo $PS1_bak | sed "s/w/w\n$(basename $1)/"`
export PS1="$PS1"
[ -f set_env.sh ] && . set_env.sh
is_set=true
return 0
fi
return 1
}
cd()
{
if [ ! -n "$1" ]
then
export PS1="$PS1_bak"
command cd
is_set=false
return
fi
if [ ! -d "$1" -a "$1" != "-" ]
then
command cd $1
return
fi
set_ok=false
cur_path=$(pwd)
command cd $1
abs_path=$(pwd)
cd_path=$(pwd -P)
command cd $cur_path
while [ -n $cd_path -a "$cd_path" != "." -a "$cd_path" != "/" ]
do
if checkExport $cd_path
then
set_ok=true
break
fi
cd_path=$(dirname $cd_path)
done
command cd $abs_path
if ! $set_ok
then
is_set=false
export PS1="$PS1_bak"
fi
}