A user on Freenode #tmux asked:
How can we properly escape this shell command using GNU awk for set -g tmux status-right
?
sensors | awk '/^Physical id 0:/ { s = $4; sub(/^+/, "", s); print s; exit }'
The result should be 45.0°C
.
Also, how can we make it update every 30 seconds?
The output of sensors
:
coretemp-isa-0000
Adapter: ISA adapter
Physical id 0: +45.0°C (high = +80.0°C, crit = +100.0°C)
...
#( )
in tmuxQuoting is complex in tmux #( )
because the contents are evaluated twice.
For this reason let's simplify the gawk program to:
sensors | awk '/^Physical id 0:/ { sub(/^+/, "", $4); print $4; exit }'
Now we plug it into .tmux.conf
:
set-option -g status-right "#( sensors | awk \\' /Physical id 0:/ { sub\\(/\+/,\"\",$4\\); print \$4; exit } \\')"
But that's terribly complex to read and change next time you go tinkering...
The easiest solution is to put the shell command into a file and call it from tmux.
~/bin/tmux-status.bash:
#!/bin/bash
sensors | awk '/^Physical id 0:/ { sub(/^+/, "", $4); print $4; exit }'
~/.tmux.conf:
set-option -g status-right "#(bash ~/bin/tmux-status.bash)"
set-option -g status-interval 30