-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc-prompt
92 lines (84 loc) · 3.38 KB
/
.bashrc-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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# http://askubuntu.com/questions/123268/changing-colors-for-user-host-directory-information-in-terminal-command-prompt
##################################################
# Fancy PWD display function
##################################################
# The home directory (HOME) is replaced with a ~
# The last pwdmaxlen characters of the PWD are displayed
# Leading partial directory names are striped off
# /home/me/stuff -> ~/stuff if USER=me
# /usr/share/big_dir_name -> ../share/big_dir_name if pwdmaxlen=20
##################################################
bash_prompt_shortener() {
# How many characters of the $PWD should be kept
local pwdmaxlen=25
# Indicate that there has been dir truncation
local trunc_symbol=".."
local dir=${PWD##*/}
pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen ))
NEW_PWD=${PWD/#$HOME/\~}
local pwdoffset=$(( ${#NEW_PWD} - pwdmaxlen ))
if [ ${pwdoffset} -gt "0" ]
then
NEW_PWD=${NEW_PWD:$pwdoffset:$pwdmaxlen}
NEW_PWD=${trunc_symbol}/${NEW_PWD#*/}
fi
}
function setPrompt {
COLOR1="\[\033[1;33m\]" #First color
COLOR2="\[\033[0;33m\]" #Second color
NO_COLOR="\[\033[0m\]" #Transparent - don't change
case $TERM in
xterm*)
TITLEBAR="\[\033]0;\W:\s\007\]"
;;
*)
TITLEBAR=""
;;
esac
local dash_open="${COLOR1}-${COLOR2}-"
local dash_close="${COLOR2}-${COLOR1}-"
local spacer="${COLOR2}-"
local jobs_and_history="${COLOR2}(${COLOR1}\!${COLOR2}:${COLOR1}\j${COLOR2})"
local user_host="${COLOR2}(${COLOR1}\u${COLOR2}@${COLOR1}\H${COLOR2})"
local host="${COLOR2}(${COLOR1}\H${COLOR2})"
local root_or_not="${COLOR2}(${COLOR1}\\\$${COLOR2})"
local cwd="${COLOR2}(${COLOR1}\w${COLOR2})"
#PS1="${TITLEBAR}${COLOR1}-${COLOR2}-(${COLOR1}\!${COLOR2}:${COLOR1}\j${COLOR2})-(${COLOR1}\w${COLOR2})-${COLOR1}-\n-${COLOR2}-(${COLOR1}\u${COLOR2}@${COLOR1}\H${COLOR2})-(${COLOR1}\\\$${COLOR2})-${COLOR1}- ${NO_COLOR}"
#PS1="${TITLEBAR}${dash_open}${cwd}${spacer}${root_or_not}${dash_close}\n${dash_open}${jobs_and_history}${spacer}${host}${dash_close}${NO_COLOR} "
#PS2="${COLOR2}--${COLOR1}- ${NO_COLOR}"
#PS1="${TITLEBAR}${COLOR1}"'${NEW_PWD}'"${COLOR2}:\$${NO_COLOR} "
#PS1="${TITLEBAR}${COLOR1}"'\h \w'"${COLOR2}:\$${NO_COLOR} "
PS1="${TITLEBAR}${COLOR1}"'\w'"${COLOR2}:\$${NO_COLOR} "
#PS2="$spacer$dash_close$NO_COLOR "
}
bash_prompt_shortener
setPrompt
unset setPrompt
#Determine and display the exit Status of the last command, if non-zero.
function checkExitStatus() {
local status="$?"
local signal=""
local COLOR1="\033[0;0;33m" #First color
local COLOR2="\033[0;0;36m" #Second color
local NO_COLOR="\033[0m" #Transparent - don't change
if [ ${status} -ne 0 -a ${status} != 128 ]; then
# If process exited by a signal, determine name of signal.
if [ ${status} -gt 128 ]; then
signal="$(builtin kill -l $((${status} - 128)) 2>/dev/null)"
if [ "$signal" ]; then
signal="$signal"
fi
fi
echo -e "${COLOR1}[Exit ${COLOR2}${status} ${signal}${COLOR1}]${NO_COLOR}" 1>&2
#echo -ne "${COLOR1}[Exit ${COLOR2}${status}${COLOR1} ${COLOR2}${signal}${COLOR1}]${NO_COLOR} " 1>&2
fi
return 0
}
print_prompt_time() {
printf "%*s\r" $(tput cols) "$(date '+%T')"
}
promptCmd() {
checkExitStatus
print_prompt_time
}
PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND$';'}promptCmd