/dev/oops

fiddyspence's blog

Hot Shell

I listen to a lot of music when I computer, which quite often means that I don’t hear it when the fans spin up because the shiny aluminium dumb terminal is having a cow because e.g. Spotify helper has gone into a tailspin. Because I spend most of my time in a terminal I thought it would be fun if my shell prompt told me when the thing got too hot. I realised subsequently that OS X has a built in say command, and made it shout that the thing was loud too, just in case red font wasn’t adequate.

Here. Have some bash and some ruby:

This goes into ~/bash_profile

trap 'for i in $(jobs -p); do kill $i; done' EXIT
export OURPORT=$(($RANDOM + 1025))
ruby ~/bin/cpucheck.rb 2> /dev/null &
cputemp ()
{
    echo $(curl --noproxy '*' -s 127.0.0.1:$OURPORT/)
}
PS1='\e[31m$([[ $(cputemp) -gt 70 ]] && echo "WARNING: HOT CPU:" && say hot cpu)\e[0m\h:\W \u\$ '

I have a ~/bin directory - this into ~/bin/cpucheck.rb (oh - and install the iStats gem)

require 'sinatra/base'
require 'iStats'
require 'iStats/cpu'
include ::IStats
class CpuServer < Sinatra::Base
  set :port, ENV['OURPORT']
  set :logging, false
  set :traps  , false
  set :server, %w[webrick]
  get '/' do
    "#{Cpu.get_cpu_temp.to_i}"
  end
  run! if app_file == $0
end

And then when the thing starts to take off:

WARNING: HOT CPU:spenceware:~ fids$