/
.bash_prompt
76 lines (66 loc) · 1.43 KB
/
.bash_prompt
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
#
# bash_prompt
#
# trims long paths down to 80 chars
_get_path(){
local x=$(pwd | sed -e "s:$HOME:~:" -e "s:$v:\$v:")
local len=${#x}
local max=80
if [ $len -gt $max ]
then
echo ...${x:((len-max+3))}
else
echo ${x}
fi
}
# prints a colour coded exit status
_get_exit_status(){
local es=$?
if [ $es -eq 0 ]
then
echo -e "${GREEN}${es}"
else
echo -e "${RED}${es}"
fi
}
# adds to the xterm title
title() {
if [ $# -eq 0 ]
then
title=""
else
title="$* - "
fi
}
# colour the host red if it is production
# all prod hostnames end with "prod"
if [[ $HOSTNAME =~ prod$ ]]
then
HOST_COLOR=$RED
else
HOST_COLOR=$GREEN
fi
# colour the user red if it is production
# all prod usernames end with "prod"
if [[ $USER =~ prod$ ]]
then
USER_COLOR=$RED
else
USER_COLOR=$GREEN
fi
#executed just before prompt
PROMPT_COMMAND='exitStatus=$(_get_exit_status);mydir=$(_get_path);'
PS1='\033]0;${title}\u@\h:`tty`>${mydir}\007\n\
\[${GREY}\][\[${BLUE}\]\t\[${GREY}\]]\
\[${GREY}\][\[${USER_COLOR}\]\u\[${GREY}\]@\[${HOST_COLOR}\]\H\[${GREY}\]] \
\[${WHITE}\]${mydir} \
\[${GREY}\](\
\[${YELLOW}\]+${SHLVL}\[${GREY}\]|\
\[${YELLOW}\]%\j\[${GREY}\]|\
\[${YELLOW}\]!\!\[${GREY}\]|\
\[${YELLOW}\]${exitStatus}\[${GREY}\])\[${NONE}\]\n\
\[${USER_COLOR}\]$\[${NONE}\] '
# continuation prompt
PS2='\[${USER_COLOR}\]>\[${NONE}\] '
#used by set -x for tracing
PS4='\[${USER_COLOR}\]+\[${NONE}\] '