Add CPU sensor script for polybar status

This commit is contained in:
Shaun Reed 2019-10-25 15:54:49 -04:00
parent db1c4bc508
commit 1c904a7254
3 changed files with 29 additions and 24 deletions

View File

@ -26,6 +26,7 @@ export EDITOR='/usr/bin/vim'
export VISUAL='/usr/bin/vim' export VISUAL='/usr/bin/vim'
export PROMPT_COMMAND="$TMUX_GITBAR_DIR/update-gitbar; $PROMPT_COMMAND" export PROMPT_COMMAND="$TMUX_GITBAR_DIR/update-gitbar; $PROMPT_COMMAND"
export PATH=$PATH":$HOME/.local/bin/i3scripts" export PATH=$PATH":$HOME/.local/bin/i3scripts"
source cpusensor
if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ tmux ]] && [ -z "$TMUX" ]; then if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ tmux ]] && [ -z "$TMUX" ]; then
exec tmux exec tmux

View File

@ -209,38 +209,19 @@ interval = 600
; CPU Temp ; CPU Temp
;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;
[module/temp-cpu] [module/temp-cpu]
type = internal/temperature type = custom/script
; Seconds to sleep between updates ; Seconds to sleep between updates
; Default: 1 ; Default: 1
interval = 0.5 interval = 0.5
; Thermal zone to use
; To list all the zone types, run
; $ for i in /sys/class/thermal/thermal_zone*; do echo "$i: $(<$i/type)"; done
; Default: 0
thermal-zone = 0
; Full path of temperature sysfs path ; Full path of temperature sysfs path
; Use `sensors` to find preferred temperature source, then run ; Use `sensors` to find preferred temperature source, then run
; $ for i in /sys/class/hwmon/hwmon*/temp*_input; do echo "$(<$(dirname $i)/name): $(cat ${i%_*}_label 2>/dev/null || echo $(basename ${i%_*})) $(readlink -f $i)"; done ; $ for i in /sys/class/hwmon/hwmon*/temp*_input; do echo "$(<$(dirname $i)/name): $(cat ${i%_*}_label 2>/dev/null || echo $(basename ${i%_*})) $(readlink -f $i)"; done
; to find path to desired file ; to find path to desired file
; Default reverts to thermal zone setting ; Default reverts to thermal zone setting
hwmon-path = /sys/devices/platform/coretemp.0/hwmon/hwmon2/temp1_input exec = exec ~/.local/bin/i3scripts/cpusensor
; Base temperature for where to start the ramp (in degrees celsius) format = <label>
; Default: 0 tail = true
base-temperature = 20 label =  %output% F°
; Threshold temperature to display warning label (in degrees celsius)
; Default: 80
warn-temperature = 60
; Available tokens:
; %temperature% (deprecated)
; %temperature-c% (default, temperature in °C)
; %temperature-f% (temperature in °F)
label =  %temperature-f%
; Available tokens:
; %temperature% (deprecated)
; %temperature-c% (default, temperature in °C)
; %temperature-f% (temperature in °F)
label-warn = %temperature-f%
label-warn-foreground = #f00
; GPU Temp ; GPU Temp
;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;

23
.local/bin/i3scripts/cpusensor Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
## Author: Shaun Reed | Contact: shaunrd0@gmail.com | URL: www.shaunreed.com ##
## ##
## A script to find and return the CPU package temp sensor ##
###############################################################################
# bash.sh
for i in /sys/class/hwmon/hwmon*/temp*_input; do
sensors+=("$(<$(dirname $i)/name): $(cat ${i%_*}_label 2>/dev/null || echo $(basename ${i%_*})) $(readlink -f $i)");
done
for i in "${sensors[@]}"
do
if [[ $i =~ ^coretemp:.Package.* ]]
then
export CPU_SENSOR=${i#*0}
fi
done
temp=$(cat $CPU_SENSOR)
imperial=$(((9/5)+32))
echo $(((temp/10000)*imperial))