# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm*) color_prompt=yes;;
esac
# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes
function load_out() {
#echo -n "$(LANG=en uptime | sed -e "s/.*load average: \(.*\...\), \(.*\...\), \(.*\...\).*/\1/" -e "s/ //g")"
awk '{ printf( "%0.2f", $1 ) }' < /proc/loadavg
}
# print + or - relative to system load tendency
function load_trend() {
awk '{ if ( $2 < $1 ) { t = "+" } else { t = "-" }; printf( "%c", t ) }' < /proc/loadavg
}
function load_color() {
gray=0
red=1
green=2
yellow=3
blue=4
magenta=5
cyan=6
white=7
# Colour progression is important ...
# bold gray -> bold green -> bold yellow -> bold red ->
# black on red -> bold white on red
#
# Then we have to choose the values at which the colours switch, with
# anything past yellow being pretty important.
tmp=$(echo $(load_out)*100 | bc)
let load100=${tmp%.*}
if [ ${load100} -lt 70 ]
then
tput bold ; tput setaf ${gray}
elif [ ${load100} -ge 70 ] && [ ${load100} -lt 120 ]
then
tput bold ; tput setaf ${green}
elif [ ${load100} -ge 120 ] && [ ${load100} -lt 200 ]
then
tput bold ; tput setaf ${yellow}
elif [ ${load100} -ge 200 ] && [ ${load100} -lt 300 ]
then
tput bold ; tput setaf ${red}
elif [ ${load100} -ge 300 ] && [ ${load100} -lt 500 ]
then
tput setaf ${gray} ; tput setab ${red}
else
tput bold ; tput setaf ${white} ; tput setab ${red}
fi
}
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
NORMAL="\[\e[00;39m\]"
RED="\[\e[01;31m\]"
GREEN="\[\e[01;32m\]"
BLUE="\[\e[01;34m\]"
BLUEBG="\[\e[01;34;01m\]"
U="\[\e[01;37;44m\]"
CYAN="\[$(tput bold ; tput setaf 6)\]"
NOCOLOUR="\[$(tput sgr0)\]"
if [ $EUID -eq 0 ]; then
USERCOLOR="$RED"
else
USERCOLOR="$GREEN"
fi
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}'"\$(load_trend)\[\$(load_color)\]\$(load_out)${NOCOLOUR} ${USERCOLOR}\u@${CYAN}\h$NORMAL:${BLUE}\w${NORMAL}\$ "
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt
# If this is an xterm set the title to user@host:dir
#case "$TERM" in
#xterm*|rxvt*)
# PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
# ;;
#*)
# ;;
#esac