DSL-N :: Adding to torsmo display in dsl-n



Afaik printf should be used over echo -n due to it being more standardized, (and therefore more portable).

Heh, maybe negatives aren't supported in the busybox version...

If you're using awk, you may as well do all of the parsing in it.

The awk thing seems to have fixed the problem - the three mini-scripts now look like this:
Code Sample
$ cat .cpufreq.sh
#!/bin/sh
cpufreq-info -mf | awk '{printf $1 " " $2}'
#
$ cat .cpugov.sh
#!/bin/sh
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor | awk '{printf $1}'
#
$ cat .laptop_mode.sh
#!/bin/sh
sudo /etc/init.d/laptop-mode status | grep "drive state is:" | cut -b22- | awk '{printf $1}'
#

...and the excerpt from .torsmorc looks like this:
Code Sample
${color red}$hr
${color grey}Uptime:   $color $uptime
${color #ddd}Battery:  $color ${battery}
${color #ddd}CPU Temp: $color ${acpitemp} degC
${color grey}CPU Freq: $color ${execi 180 ~/.cpufreq.sh}
${color grey}CPU Govn: $color ${execi 180 ~/.cpugov.sh}
${color grey}/dev/hda: $color ${execi 180 ~/.laptop_mode.sh}
${color green}$hr$color


Quote
If you're using awk, you may as well do all of the parsing in it.

- after looking at the awk statement in .torsmo_ip I can believe you're right, but after staring at it for 30mins I wasn't feeling much enlightenment  :)

To pass the output to a var:
VAR=`echo Yeah`

In case it helps in future, to get rid of newlines in a pipe without invoking awk or sed or somesuch, do:

Code Sample
 echo 123 | tr -d '\n'


tr is probably more efficient (not that it probably matters much in this case).

Re:

Code Sample
sudo /etc/init.d/laptop-mode status | grep "drive state is:" | cut -b22- | awk '{printf $1}'


This can probably be contracted to:

Code Sample
sudo /etc/init.d/laptop-mode status | awk  '/drive state is/{printf $4}'

Thanks - the 3 mini-scripts now look like this:
Code Sample
$ cat .cpufreq.sh
#!/bin/sh
cpufreq-info -mf | tr -d '\n'
#
$ cat .cpugov.sh
#!/bin/sh
cpufreq-info -p | awk '{printf $3}'
#
$ cat .laptop_mode.sh
#!/bin/sh
sudo /etc/init.d/laptop-mode status | awk '/drive state is/{printf $4}'
#

Next Page...
original here.