I made a couple pipe menus for Openbox over the last couple of days, which was fun as I knew nothing about bash previously. One displayed the output of df but it seems a limit to menu width undermined this. This one, on the other hand, works like a dandy for me. I don't understand entirely how it works, so for the sake of my own bash/awk education, I ask you, can it be simplified without using bc or acpi or something else I might not have installed?
Code:
#!/bin/sh
now=`cat /sys/class/power_supply/BAT0/charge_now`
full=`cat /sys/class/power_supply/BAT0/charge_full`
Date=$(date '+%R %a %x')
Wifi=$(cat /proc/net/wireless | awk 'NR==3 {print $3}')
Batt=$(echo $now $full | awk '{ printf("%.2f\n", $1/$2 * 100) }')
echo "<openbox_pipe_menu>"
echo "<separator label=\"$Date\"/>"
echo "<separator />"
echo "<item label=\"Wifi: $Wifi%\"/>"
echo "<item label=\"Batt: $Batt%\"/>"
echo "</openbox_pipe_menu>"