Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- [`dropbox_status.sh`](segments/dropbox_status.sh) a new segment showing Dropbox operation statuses. [#478](https://github.com/erikw/tmux-powerline/pull/478)
- 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)
- 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)
- [`cpu_temp.sh`](segments/cpu_temp.sh): CPU temperature. [#495](https://github.com/erikw/tmux-powerline/pull/495)
### Changed
- **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.
Please update your custom themes and segments now. [#489](https://github.com/erikw/tmux-powerline/pull/489)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ Requirements for the lib to work are:
## Segment Requirements
Some segments have their own requirements. If you enable them in your theme, make sure all requirements are met for those.

* **cpu_temp.sh**: `lm_sensors` for Linux, `smctemp` for Macos
* **dropbox_status.sh**: `dropbox-cli`
* **github_notifications.sh**: `jq`, `curl`
* **ifstat.sh**: `ifstat` (there is a simpler segment `ifstat_sys.sh` not using ifstat)
Expand Down
16 changes: 16 additions & 0 deletions lib/cpu_temp_helper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# shellcheck shell=bash

tp_cpu_temp_value() {
if tp_shell_is_macos; then
smctemp -c | bc -l
elif tp_shell_is_linux; then
sensors \
| grep "$TMUX_POWERLINE_SEG_CPU_TEMP_SENSORS_LINE_MARKER" -m 1 \
| sed -e 's/[^+]*+\([\s0-9\.]*\).*/\1/' | bc -l
fi
}

tp_cpu_temp_is_high() {
echo "$(tp_cpu_temp_value) >= $TMUX_POWERLINE_SEG_CPU_TEMP_HIGH" | bc -l
}

2 changes: 2 additions & 0 deletions lib/headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ source "${TMUX_POWERLINE_DIR_LIB}/muting.sh"
source "${TMUX_POWERLINE_DIR_LIB}/powerline.sh"
# shellcheck source=lib/config_file.sh
source "${TMUX_POWERLINE_DIR_LIB}/config_file.sh"
# shellcheck source=lib/cpu_temp_helper.sh
source "${TMUX_POWERLINE_DIR_LIB}/cpu_temp_helper.sh"
34 changes: 34 additions & 0 deletions segments/cpu_temp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# shellcheck shell=bash
# Prints CPU temperature
# Requirements:
# lm_sensors (Linux only)
# smctemp (Macos only)

TMUX_POWERLINE_SEG_CPU_TEMP_HIGH=${TMUX_POWERLINE_SEG_CPU_TEMP_HIGH:-60}
TMUX_POWERLINE_SEG_CPU_TEMP_ICON="${TMUX_POWERLINE_SEG_CPU_TEMP_ICON:- }"
TMUX_POWERLINE_SEG_CPU_TEMP_SENSORS_LINE_MARKER="${TMUX_POWERLINE_SEG_CPU_TEMP_SENSORS_LINE_MARKER:-Package id 0\|Physical id 0\|temp1}"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current default value, is this one grep pattern that works for smctemp or sensors?

Could there be 2 default values set depending on tp_shell_is_linux() or similar?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only for 'sensors'.


generate_segmentrc() {
read -r -d '' rccontents <<EORC
# The minimum temperature considered "high" by tp_cpu_temp_is_high function
export TMUX_POWERLINE_SEG_CPU_TEMP_HIGH=${TMUX_POWERLINE_SEG_CPU_TEMP_HIGH}
# CPU temperature icon
export TMUX_POWERLINE_SEG_CPU_TEMP_ICON="${TMUX_POWERLINE_SEG_CPU_TEMP_ICON}"
# Regexp to indicate a line containing CPU temperature in sensors output
export TMUX_POWERLINE_SEG_CPU_TEMP_SENSORS_LINE_MARKER="${TMUX_POWERLINE_SEG_CPU_TEMP_SENSORS_LINE_MARKER}"
EORC
echo "$rccontents"
}

run_segment() {
local temp
temp=$(tp_cpu_temp_value)

if [ -n "$temp" ]; then
echo "${TMUX_POWERLINE_SEG_CPU_TEMP_ICON}${temp}°"
return 0
else
return 1
fi
}

7 changes: 7 additions & 0 deletions themes/default.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,13 @@ if [ -z "$TMUX_POWERLINE_RIGHT_STATUS_SEGMENTS" ]; then
#"air ${TMUX_POWERLINE_SEG_AIR_COLOR} 255"
"weather 37 255"
#"rainbarf 0 ${TMUX_POWERLINE_DEFAULT_FOREGROUND_COLOR}"
# "$(
# if (($(tp_cpu_temp_is_high))); then
# echo "cpu_temp #ff2020 235"
# else
# echo "cpu_temp #303080 136"
# fi
# )" \
#"xkb_layout 125 117"
#"tmux_continuum_save"
#"tmux_continuum_status 14 7"
Expand Down