From 454dfddd44b54f33fc3a95c22aa8a893de45d7e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Schmidts?= Date: Sun, 21 Apr 2013 16:16:06 +0200 Subject: [PATCH 1/4] implementing a temp monitoring solution --- liquidprompt | 73 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 46 insertions(+), 27 deletions(-) diff --git a/liquidprompt b/liquidprompt index 1ce6e72..c5315c0 100755 --- a/liquidprompt +++ b/liquidprompt @@ -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}" From 43e426d0e87aaf3aeae154064753ea89c26fe9c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Schmidts?= Date: Mon, 22 Apr 2013 23:22:32 +0200 Subject: [PATCH 2/4] add configuration options and temperature mark --- liquid.theme | 2 ++ liquidprompt | 12 +++++++----- liquidpromptrc-dist | 3 +++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/liquid.theme b/liquid.theme index 70334b5..db90580 100644 --- a/liquid.theme +++ b/liquid.theme @@ -13,6 +13,7 @@ if [[ "$(locale -k LC_CTYPE | sed -n 's/^charmap="\(.*\)"/\1/p')" == *"UTF-8"* ] LP_MARK_BATTERY="⌁" # in front of the battery charge LP_MARK_ADAPTER="⏚" # displayed when plugged LP_MARK_LOAD="⌂" # in front of the load + LP_MARK_TEMP="θ" # in front of the temp LP_MARK_PROXY="↥" # indicate a proxy in use LP_MARK_HG="☿" # prompt mark in hg repositories LP_MARK_SVN="‡" # prompt mark in svn repositories @@ -26,6 +27,7 @@ else LP_MARK_BATTERY="b" LP_MARK_ADAPTER="p" LP_MARK_LOAD="c" + LP_MARK_TEMP="T" LP_MARK_PROXY="^" LP_MARK_HG="m" LP_MARK_SVN="=" diff --git a/liquidprompt b/liquidprompt index c5315c0..8ac4e04 100755 --- a/liquidprompt +++ b/liquidprompt @@ -233,6 +233,7 @@ _lp_source_config() LP_MARK_BATTERY=${LP_MARK_BATTERY:-"⌁"} LP_MARK_ADAPTER=${LP_MARK_ADAPTER:-"⏚"} LP_MARK_LOAD=${LP_MARK_LOAD:-"⌂"} + LP_MARK_TEMP=${LP_MARK_TEMP:-"θ"} LP_MARK_PROXY=${LP_MARK_PROXY:-"↥"} LP_MARK_HG=${LP_MARK_HG:-"☿"} LP_MARK_SVN=${LP_MARK_SVN:-"‡"} @@ -1199,18 +1200,19 @@ _lp_load_color() fi } -_lp_temp() { +_lp_temperature() { [[ "$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 + for i in $(sensors | grep -E "^(Core|temp)" | + sed -r "s/.*: *\+([0-9]*)\..°.*/\1/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}" + echo -ne "$(_lp_color_map $temperature)${LP_MARK_TEMP}$temperature°${NO_COL}" fi } @@ -1396,7 +1398,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_TEMP=$(_lp_sr "$(_lp_temperature)") LP_LOAD=$(_lp_sr "$(_lp_load_color)") LP_BATT=$(_lp_sr "$(_lp_battery_color)") LP_TIME=$(_lp_sr "$(_lp_time)") diff --git a/liquidpromptrc-dist b/liquidpromptrc-dist index 2677855..6029fb0 100644 --- a/liquidpromptrc-dist +++ b/liquidpromptrc-dist @@ -95,6 +95,9 @@ LP_ENABLE_BZR=1 # Recommended value is 0 LP_ENABLE_TIME=0 +# Show average system temperature +LP_ENABLE_TEMP=1 + # When showing time, use an analog clock instead of numeric values. # The analog clock is "accurate" to the nearest half hour. # You must have a unicode-capable terminal and a font with the "CLOCK" From e35c90318e3f2de9efde2d273ceaff1ed579df7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Schmidts?= Date: Mon, 22 Apr 2013 23:32:50 +0200 Subject: [PATCH 3/4] prevent the feature from breaking systems that can't run the "sensors" command --- liquidprompt | 1 + 1 file changed, 1 insertion(+) diff --git a/liquidprompt b/liquidprompt index 8ac4e04..811c995 100755 --- a/liquidprompt +++ b/liquidprompt @@ -322,6 +322,7 @@ unset _lp_source_config [[ "$LP_ENABLE_HG" = 1 ]] && { command -v hg >/dev/null || LP_ENABLE_HG=0 ; } [[ "$LP_ENABLE_BZR" = 1 ]] && { command -v bzr > /dev/null || LP_ENABLE_BZR=0 ; } [[ "$LP_ENABLE_BATT" = 1 ]] && { command -v acpi >/dev/null || LP_ENABLE_BATT=0 ; } +[[ "$LP_ENABLE_TEMP" = 1 ]] && { command -v sensors >/dev/null || LP_ENABLE_TEMP=0 ; } # Escape the given strings # Must be used for all strings that may comes from remote sources, From 75c346feb4cb0cac0ffd13a81f6286533778de72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Schmidts?= Date: Wed, 24 Apr 2013 09:48:18 +0200 Subject: [PATCH 4/4] add commentaries and a selection process for temperature source * add a function selection process at loading time so liquidprompt can use other command than sensors to get temperature * add commentaries --- liquidprompt | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/liquidprompt b/liquidprompt index 811c995..2b87d3e 100755 --- a/liquidprompt +++ b/liquidprompt @@ -322,7 +322,6 @@ unset _lp_source_config [[ "$LP_ENABLE_HG" = 1 ]] && { command -v hg >/dev/null || LP_ENABLE_HG=0 ; } [[ "$LP_ENABLE_BZR" = 1 ]] && { command -v bzr > /dev/null || LP_ENABLE_BZR=0 ; } [[ "$LP_ENABLE_BATT" = 1 ]] && { command -v acpi >/dev/null || LP_ENABLE_BATT=0 ; } -[[ "$LP_ENABLE_TEMP" = 1 ]] && { command -v sensors >/dev/null || LP_ENABLE_TEMP=0 ; } # Escape the given strings # Must be used for all strings that may comes from remote sources, @@ -1138,11 +1137,6 @@ _lp_battery_color() fi # ret } - -############### -# System load # -############### - _lp_color_map() { if [[ $1 -ge 0 ]] && [[ $1 -lt 20 ]] ; then echo -ne "${LP_COLORMAP_0}" @@ -1169,6 +1163,10 @@ _lp_color_map() { fi } +############### +# System load # +############### + # Compute a gradient of background/forground colors depending on the battery status _lp_load_color() { @@ -1201,9 +1199,12 @@ _lp_load_color() fi } -_lp_temperature() { - [[ "$LP_ENABLE_TEMP" != 1 ]] && return +###################### +# System temperature # +###################### +_lp_temp_sensors() { + # Return the average system temperature we get through the sensors command local count=0 local temperature=0 for i in $(sensors | grep -E "^(Core|temp)" | @@ -1211,13 +1212,32 @@ _lp_temperature() { temperature=$(($temperature+$i)) count=$(($count+1)) done - temperature=$(($temperature/$count)) + echo -ne "$(($temperature/$count))" +} + +# Will set _lp_temp_function so the temperature monitoring feature use an +# available command. _lp_temp_function should return only a numeric value +if [[ "$LP_ENABLE_TEMP" = 1 ]]; then + if command -v sensors >/dev/null; then + _lp_temp_function=_lp_temp_sensors + # elif command -v the_command_you_want_to_use; then + # _lp_temp_function=your_function + else + LP_ENABLE_TEMP=0 + fi +fi + +_lp_temperature() { + # Will display the numeric value as we got it through the _lp_temp_function + # and colorize it through _lp_color_map. + [[ "$LP_ENABLE_TEMP" != 1 ]] && return + + temperature=$($_lp_temp_function) if [[ $temperature -ge $LP_TEMP_THRESHOLD ]]; then echo -ne "$(_lp_color_map $temperature)${LP_MARK_TEMP}$temperature°${NO_COL}" fi } - ########## # DESIGN # ##########