The current loop is a bit awkward for a number of reasons:
* iostat exits after a number of iterations, so to keep the script
going we need to run it in a nested loop;
* we also run iostat concurrently using the |& syntax, which in
addition to being non-portable requires us to set up a cleanup
path so that we don't leave stray processes around when spectrwm
is restarted;
* due to the fact that iostat prints its headers again every 20
records, we have to keep careful track of the number of
iterations - something which has proven to be error-prone.
Once we do away with the idea of iostat driving the update loop, all
of these issues disappear and the code becomes much simpler.
We still cache battery data for 11 seconds, which is the same amount
as before; tweaking it further, if desired, will be trivial now.
This patch is better viewed with 'git show -w'.
If the CPU is throttled to less than 1 GHz, the contents of the
bar will move around a bit; always use 4 digits to print the CPU
frequency so that doesn't happen.
The idea is that it's pointless to collect information about the
battery every single second, so caching has been implemented for
the output of apm; however, the condition has been broken since
3356f1ccd4, which resulted in data being collected every single
second after all.
This fixes the check so that information is collected every 11
seconds, which fits nicely into the 22 second long cycle used to
parse iostat's output.
1. Do not hardcode path to coreutils.
2. Do not pass variables to functions where not required.
3. Run top as a batch process to be able to grep its output.