Skip to content

Commit 87c9014

Browse files
authored
Merge pull request #495 from iyegoroff/cpu_temp
CPU temperature segment
2 parents 19d6884 + ef5c83c commit 87c9014

File tree

6 files changed

+71
-0
lines changed

6 files changed

+71
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1212
- [`dropbox_status.sh`](segments/dropbox_status.sh) a new segment showing Dropbox operation statuses. [#478](https://github.com/erikw/tmux-powerline/pull/478)
1313
- Proper error logging in segments with function `tp_err_seg()`. [#486](https://github.com/erikw/tmux-powerline/pull/486) [#485](https://github.com/erikw/tmux-powerline/pull/485)
1414
- Adapter segments for [tmux-continuum](https://github.com/tmux-plugins/tmux-continuum/): [`tmux_continuum_save.sh`](segments/tmux_continuum_save.sh) and [`tmux_continuum_status.sh`](segments/tmux_continuum_status.sh) [#493](https://github.com/erikw/tmux-powerline/pull/493)
15+
- [`cpu_temp.sh`](segments/cpu_temp.sh): CPU temperature. [#495](https://github.com/erikw/tmux-powerline/pull/495)
1516
### Changed
1617
- **Deprecation Warning:** functions `patched_font_in_use()`, `air_color()` and `format()` have been replaced by `tp_patched_font_in_use()`, `tp_air_color()` and `tp_format()` respectively and will be removed in future releases.
1718
Please update your custom themes and segments now. [#489](https://github.com/erikw/tmux-powerline/pull/489)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ Requirements for the lib to work are:
103103
## Segment Requirements
104104
Some segments have their own requirements. If you enable them in your theme, make sure all requirements are met for those.
105105

106+
* **cpu_temp.sh**: `lm_sensors` for Linux, [smctemp](https://github.com/narugit/smctemp) for Macos
106107
* **dropbox_status.sh**: `dropbox-cli`
107108
* **github_notifications.sh**: `jq`, `curl`
108109
* **ifstat.sh**: `ifstat` (there is a simpler segment `ifstat_sys.sh` not using ifstat)

lib/cpu_temp_helper.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# shellcheck shell=bash
2+
3+
tp_cpu_temp_value() {
4+
if tp_shell_is_macos; then
5+
smctemp -c | bc -l
6+
elif tp_shell_is_linux; then
7+
sensors \
8+
| grep "$TMUX_POWERLINE_SEG_CPU_TEMP_SENSORS_LINE_MARKER" -m 1 \
9+
| sed -e 's/[^+]*+\([\s0-9\.]*\).*/\1/' | bc -l
10+
fi
11+
}
12+
13+
tp_cpu_temp_at_least() {
14+
echo "$(tp_cpu_temp_value) >= $1" | bc -l
15+
}
16+

lib/headers.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ source "${TMUX_POWERLINE_DIR_LIB}/muting.sh"
2626
source "${TMUX_POWERLINE_DIR_LIB}/powerline.sh"
2727
# shellcheck source=lib/config_file.sh
2828
source "${TMUX_POWERLINE_DIR_LIB}/config_file.sh"
29+
# shellcheck source=lib/cpu_temp_helper.sh
30+
source "${TMUX_POWERLINE_DIR_LIB}/cpu_temp_helper.sh"

segments/cpu_temp.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# shellcheck shell=bash
2+
# Prints CPU temperature
3+
# Requirements:
4+
# lm_sensors (Linux only)
5+
# smctemp (Macos only)
6+
7+
TMUX_POWERLINE_SEG_CPU_TEMP_ICON_DEFAULT=""
8+
TMUX_POWERLINE_SEG_CPU_TEMP_SENSORS_LINE_MARKER_DEFAULT="Package id 0\|Physical id 0\|temp1"
9+
10+
generate_segmentrc() {
11+
read -r -d '' rccontents <<EORC
12+
# CPU temperature icon
13+
export TMUX_POWERLINE_SEG_CPU_TEMP_ICON="${TMUX_POWERLINE_SEG_CPU_TEMP_ICON_DEFAULT}"
14+
# Linux only. Regexp to indicate a line containing CPU temperature in 'sensors' output.
15+
# Check the output of 'sensors' program, decide which line contains desired CPU temperature
16+
# and store an unique part of that line in this variable. It will be used by 'grep' program
17+
# to distinct the 'CPU temperature' line from the rest output lines.
18+
export TMUX_POWERLINE_SEG_CPU_TEMP_SENSORS_LINE_MARKER="${TMUX_POWERLINE_SEG_CPU_TEMP_SENSORS_LINE_MARKER_DEFAULT}"
19+
EORC
20+
echo "$rccontents"
21+
}
22+
23+
run_segment() {
24+
__process_settings
25+
26+
local temp
27+
temp=$(tp_cpu_temp_value)
28+
29+
if [ -n "$temp" ]; then
30+
echo "${TMUX_POWERLINE_SEG_CPU_TEMP_ICON}${temp}°"
31+
return 0
32+
else
33+
return 1
34+
fi
35+
}
36+
37+
__process_settings() {
38+
if [ -z "$TMUX_POWERLINE_SEG_CPU_TEMP_ICON" ]; then
39+
export TMUX_POWERLINE_SEG_CPU_TEMP_ICON="${TMUX_POWERLINE_SEG_CPU_TEMP_ICON_DEFAULT}"
40+
fi
41+
if [ -z "$TMUX_POWERLINE_SEG_CPU_TEMP_SENSORS_LINE_MARKER" ]; then
42+
export TMUX_POWERLINE_SEG_CPU_TEMP_SENSORS_LINE_MARKER="${TMUX_POWERLINE_SEG_CPU_TEMP_SENSORS_LINE_MARKER_DEFAULT}"
43+
fi
44+
}

themes/default.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,13 @@ if [ -z "$TMUX_POWERLINE_RIGHT_STATUS_SEGMENTS" ]; then
133133
#"air ${TMUX_POWERLINE_SEG_AIR_COLOR} 255"
134134
"weather 37 255"
135135
#"rainbarf 0 ${TMUX_POWERLINE_DEFAULT_FOREGROUND_COLOR}"
136+
# "$(
137+
# if (($(tp_cpu_temp_at_least 60))); then
138+
# echo "cpu_temp #ff2020 235"
139+
# else
140+
# echo "cpu_temp #303080 136"
141+
# fi
142+
# )" \
136143
#"xkb_layout 125 117"
137144
#"tmux_continuum_save"
138145
#"tmux_continuum_status 14 7"

0 commit comments

Comments
 (0)