implementing a temp monitoring solution

This commit is contained in:
François Schmidts 2013-04-21 16:16:06 +02:00
parent f483697fda
commit 454dfddd44

View File

@ -196,6 +196,7 @@ _lp_source_config()
# Default values (globals)
LP_BATTERY_THRESHOLD=${LP_BATTERY_THRESHOLD:-75}
LP_LOAD_THRESHOLD=${LP_LOAD_THRESHOLD:-60}
LP_TEMP_THRESHOLD=${LP_TEMP_THRESHOLD:-60}
LP_PATH_LENGTH=${LP_PATH_LENGTH:-35}
LP_PATH_KEEP=${LP_PATH_KEEP:-2}
LP_HOSTNAME_ALWAYS=${LP_HOSTNAME_ALWAYS:-0}
@ -211,6 +212,7 @@ _lp_source_config()
LP_ENABLE_PERM=${LP_ENABLE_PERM:-1}
LP_ENABLE_SHORTEN_PATH=${LP_ENABLE_SHORTEN_PATH:-1}
LP_ENABLE_PROXY=${LP_ENABLE_PROXY:-1}
LP_ENABLE_TEMP=${LP_ENABLE_TEMP:-1}
LP_ENABLE_JOBS=${LP_ENABLE_JOBS:-1}
LP_ENABLE_LOAD=${LP_ENABLE_LOAD:-1}
LP_ENABLE_BATT=${LP_ENABLE_BATT:-1}
@ -1139,6 +1141,32 @@ _lp_battery_color()
# System load #
###############
_lp_color_map() {
if [[ $1 -ge 0 ]] && [[ $1 -lt 20 ]] ; then
echo -ne "${LP_COLORMAP_0}"
elif [[ $1 -ge 20 ]] && [[ $1 -lt 40 ]] ; then
echo -ne "${LP_COLORMAP_1}"
elif [[ $1 -ge 40 ]] && [[ $1 -lt 60 ]] ; then
echo -ne "${LP_COLORMAP_2}"
elif [[ $1 -ge 60 ]] && [[ $1 -lt 80 ]] ; then
echo -ne "${LP_COLORMAP_3}"
elif [[ $1 -ge 80 ]] && [[ $1 -lt 100 ]] ; then
echo -ne "${LP_COLORMAP_4}"
elif [[ $1 -ge 100 ]] && [[ $1 -lt 120 ]] ; then
echo -ne "${LP_COLORMAP_5}"
elif [[ $1 -ge 120 ]] && [[ $1 -lt 140 ]] ; then
echo -ne "${LP_COLORMAP_6}"
elif [[ $1 -ge 140 ]] && [[ $1 -lt 160 ]] ; then
echo -ne "${LP_COLORMAP_7}"
elif [[ $1 -ge 160 ]] && [[ $1 -lt 180 ]] ; then
echo -ne "${LP_COLORMAP_8}"
elif [[ $1 -ge 180 ]] ; then
echo -ne "${LP_COLORMAP_9}"
else
echo -ne "${LP_COLORMAP_0}"
fi
}
# Compute a gradient of background/forground colors depending on the battery status
_lp_load_color()
{
@ -1158,32 +1186,7 @@ _lp_load_color()
if [[ $load -ge $LP_LOAD_THRESHOLD ]]
then
local ret
ret=""
if [[ $load -ge 0 ]] && [[ $load -lt 20 ]] ; then
ret="${ret}${LP_COLORMAP_0}"
elif [[ $load -ge 20 ]] && [[ $load -lt 40 ]] ; then
ret="${ret}${LP_COLORMAP_1}"
elif [[ $load -ge 40 ]] && [[ $load -lt 60 ]] ; then
ret="${ret}${LP_COLORMAP_2}"
elif [[ $load -ge 60 ]] && [[ $load -lt 80 ]] ; then
ret="${ret}${LP_COLORMAP_3}"
elif [[ $load -ge 80 ]] && [[ $load -lt 100 ]] ; then
ret="${ret}${LP_COLORMAP_4}"
elif [[ $load -ge 100 ]] && [[ $load -lt 120 ]] ; then
ret="${ret}${LP_COLORMAP_5}"
elif [[ $load -ge 120 ]] && [[ $load -lt 140 ]] ; then
ret="${ret}${LP_COLORMAP_6}"
elif [[ $load -ge 140 ]] && [[ $load -lt 160 ]] ; then
ret="${ret}${LP_COLORMAP_7}"
elif [[ $load -ge 160 ]] && [[ $load -lt 180 ]] ; then
ret="${ret}${LP_COLORMAP_8}"
elif [[ $load -ge 180 ]] ; then
ret="${ret}${LP_COLORMAP_9}"
else
ret="${ret}${LP_COLORMAP_0}"
fi
ret="$ret${LP_MARK_LOAD}"
local ret="$(_lp_color_map $load) ${LP_MARK_LOAD}"
if [[ "$LP_PERCENTS_ALWAYS" -eq "1" ]]; then
if [[ "$_LP_WORKING_SHELL" == "bash" ]]; then
@ -1196,6 +1199,21 @@ _lp_load_color()
fi
}
_lp_temp() {
[[ "$LP_ENABLE_TEMP" != 1 ]] && return
local count=0
local temperature=0
for i in $(sensors | grep -E "Core" |
sed -e 's/.*: *+//g' -e 's/\..°.*//g'); do
temperature=$(($temperature+$i))
count=$(($count+1))
done
temperature=$(($temperature/$count))
if [[ $temperature -ge $LP_TEMP_THRESHOLD ]]; then
echo -ne "$(_lp_color_map $temperature)$temperature°${NO_COL}"
fi
}
##########
# DESIGN #
@ -1378,6 +1396,7 @@ _lp_set_prompt()
# left of main prompt: space at right
LP_JOBS=$(_lp_sr "$(_lp_jobcount_color)")
LP_TEMP=$(_lp_sr "$(_lp_temp)")
LP_LOAD=$(_lp_sr "$(_lp_load_color)")
LP_BATT=$(_lp_sr "$(_lp_battery_color)")
LP_TIME=$(_lp_sr "$(_lp_time)")
@ -1458,7 +1477,7 @@ _lp_set_prompt()
if [[ -z $LP_PS1 ]] ; then
# add title escape time, jobs, load and battery
PS1="${LP_PS1_PREFIX}${LP_TIME}${LP_BATT}${LP_LOAD}${LP_JOBS}"
PS1="${LP_PS1_PREFIX}${LP_TIME}${LP_BATT}${LP_LOAD}${LP_JOBS}${LP_TEMP}"
# add user, host and permissions colon
PS1="${PS1}${LP_MARK_BRACKET_OPEN}${LP_USER}${LP_HOST}${LP_PERM}"