cmw1mq
Last Updated: February 25, 2016
·
2.513K
· passcod
11904d2d1af36d532f9d78d9d59f6819

CPU temperature segment in tmux powerline

Firstly, if you don't have the tmux-powerline this protip is not for you. (But you can go install it and come back later!)

Secondly, you're going to need the smc command-line utility. You can either compile it yourself, which I haven't managed to do, probably because Makefiles hate me, or you can download smcFanControl and find the smc binary within that. Whichever way you go, you'll need to note the path to the executable.

Now then. In your tmux-powerline/segments folder, create a temperature_mac.sh file containing:

#!/usr/bin/env bash

# Path to `smc` binary
smc="/Applications/smcFanControl.app/Contents/Resources/smc"

# Sensor to use. List is available at:
# https://github.com/hholtmann/smcFanControl/blob/master/smc-command/README#L74
sensor=TC0P

echo -n "∆ "

$smc -k $sensor -r | \
sed 's/.*bytes \(.*\))/\1/' | \
sed 's/\([0-9a-fA-F]*\)/0x\1/g' | \
perl -ne 'chomp; ($low,$high) = split(/ /); print "1k"; print (((hex($low)*256)+hex($high))/4/64); print " 1/n\n";' | \
dc

echo "°C"

and create the corresponding segment in status-{left|right}.sh:

declare -A temperature
if [ "$PLATFORM" == "mac" ]; then
    temperature+=(["script"]="${segments_path}/temperature_mac.sh")
else
    temperature+=(["script"]="${segments_path}/temperature.sh")
fi
temperature+=(["foreground"]="colour255")
temperature+=(["background"]="colour127")
temperature+=(["separator"]="${separator_left_bold}")
register_segment "temperature"

I don't have a Linux box to develop the temperature.sh script under, so if someone here has one and is willing to contribute, that'd be awesome. For the moment, here's how it looks in OS X (in the middle):

cpu-temperature-tmux-powerline-display

(Über-thonks to mrmekon for the temperature parsing one-liner used in the script.)

Say Thanks
Respond

1 Response
Add your response

22765
B451817e013f2084e84990d7b7d36b21

I've never used shell scripts like this one but python files. All I have is ~/.config/powerline/tmux/my.json and ~/.config/powerline/segments/ with __init__.py and a self written python module in it.
How can I use shell scripts and how can I embed them into my json file?

over 1 year ago ·