-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprompt
59 lines (56 loc) · 1.35 KB
/
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
function my_timer_start {
my_timer=${my_timer:-$SECONDS}
}
function my_timer_stop {
my_time=$(( $SECONDS - $my_timer ))
if (( $my_time > 59 )); then
local s=$(( $my_time % 60 ))
local m=$(( $my_time / 60 ))
if (( $m > 59 )); then
local m=$(( $m % 60 ))
local h=$(( $my_time / 3600 ))
my_time=$h':'$m':'$s
else
my_time=$m':'$s
fi
fi
unset my_timer
}
function my_prompt {
local exit_status="$?"
my_timer_stop
local default_user="esert";
local RED="\[\033[1;31m\]"
local OFF="\[\033[0m\]"
if [ "$USER" != "$default_user" ]; then
if [ "$exit_status" != "0" ]; then
if [ "$my_time" != "0" ]; then
PS1="${RED}USER: \u${OFF}\n${RED}ERROR: ${exit_status}${OFF}\n\h:\w[$my_time]\$ "
else
PS1="${RED}USER: \u${OFF}\n${RED}ERROR: ${exit_status}${OFF}\n\h:\w\$ "
fi
else
if [ "$my_time" != "0" ]; then
PS1="${RED}USER: \u${OFF}\n\h:\w[$my_time]\$ "
else
PS1="${RED}USER: \u${OFF}\n\h:\w\$ "
fi
fi
else
if [ "$exit_status" != "0" ]; then
if [ "$my_time" != "0" ]; then
PS1="${RED}ERROR: ${exit_status}${OFF}\n\h:\w[$my_time]\$ "
else
PS1="${RED}ERROR: ${exit_status}${OFF}\n\h:\w\$ "
fi
else
if [ "$my_time" != "0" ]; then
PS1="\h:\w[$my_time]\$ "
else
PS1="\h:\w\$ "
fi
fi
fi
}
trap 'my_timer_start' DEBUG
PROMPT_COMMAND=my_prompt