You are not logged in.
cellout is a simple battery status printer for the console, written in POSIX awk.
Usage:
cellout [-g] battery
Example output for 97% capacity, charging:
97C
Example output with graphical charge meter for 49% capacity, discharging:
[##--] 49D
It is available on the AUR at https://aur.archlinux.org/packages.php?ID=59222.
Feedback appreciated!
Last edited by neurolysis (2012-05-24 10:40:49)
Offline
Ah, so that's how you work out the battery charge! Some quick comments:
- I'm getting the graphical charge meter regardless of whether I specify -g or not.
- Graphical charge meter would be more reasonable in 10% steps; 25% is too coarse.
- Could you assume battery is always BATn so you just need to specify n on the command line?
- Defaulting battery to BAT0 would be convenient
Offline
Ah, so that's how you work out the battery charge! Some quick comments:
- I'm getting the graphical charge meter regardless of whether I specify -g or not.
Can't reproduce this... odd.
$ cellout BAT1
100F
$ cellout -g BAT1
[####] 100F
- Graphical charge meter would be more reasonable in 10% steps; 25% is too coarse.
Fundamentally disagree from a usability perspective, it should be readable at a glance with accuracy provided by the numeric output. Perhaps 5 steps would be better, but I don't know.
- Could you assume battery is always BATn so you just need to specify n on the command line?
It isn't always (I've had computers where it is called other things, for example, ACAD0).
- Defaulting battery to BAT0 would be convenient
I really don't like implicit defaults from a usability perspective, I find them kind of against my philosophy.
Thanks for the feedback!
Last edited by neurolysis (2012-05-13 03:59:45)
Offline
Nice app.
I'm getting the graphical charge meter regardless of whether I specify -g or not.
Same issue here:
┌─[Archer ~]
└─╼ cellout BAT0
[####] 100F
┌─[Archer ~]
└─╼ cellout -g BAT0
Could not read /sys/class/power_supply/-g/charge_full
Offline
Offline
I really don't understand why that is happening, it doesn't happen for me. Although, having said that, where is this "Could not read" text coming from? That's not anywhere in the source...
Last edited by neurolysis (2012-05-22 18:33:31)
Offline
I assumed it had something to do with an error relating to the path
Could not read /sys/class/power_supply/-g/charge_full
...the -g switch is being dumped in there somehow.
Offline
I assumed it had something to do with an error relating to the path
Could not read /sys/class/power_supply/-g/charge_full
...the -g switch is being dumped in there somehow.
Yes, but I have no string in the source that says "Could not read ...".
Last edited by neurolysis (2012-05-22 21:08:28)
Offline
This?
┌─[Veles ~]
└─╼ grep -R "Could not read" Build/cellout/
Build/cellout/src/cellout: [ -r "${_file}" ] || _die "Could not read ${_file}"
Build/cellout/pkg/usr/bin/cellout: [ -r "${_file}" ] || _die "Could not read ${_file}"
Offline
Here my experiences:
When I suspend and then resume the charge filenames change.
The variables given by 'uevent' change as well.
Must be a kernel bug; but I didn't have the time to report it yet, and I haven't reported any bug til now, and am not sure how to do it.
I use a simple shell script for my battery status needs:
. "/sys/bus/acpi/drivers/battery/PNP0C0A:00/power_supply/BAT0/uevent"
[ -z "${POWER_SUPPLY_ENERGY_NOW}" ] && prefix=CHARGE || prefix=ENERGY
eval now=\${POWER_SUPPLY_${prefix}_NOW}
eval full=\${POWER_SUPPLY_${prefix}_FULL}
eval full_design=\${POWER_SUPPLY_${prefix}_FULL_DESIGN}
Solves it for my needs at the moment, maybe you can check for the filenames, too?
Edit for clarity: after resume, /sys/class/power_supply/foo/charge_full might become /sys/class/power_supply/foo/energy_full (or the other way around, no battery plugged in atm, so can't check)
Last edited by dammannj (2012-05-22 22:13:46)
Offline
This?
┌─[Veles ~] └─╼ grep -R "Could not read" Build/cellout/ Build/cellout/src/cellout: [ -r "${_file}" ] || _die "Could not read ${_file}" Build/cellout/pkg/usr/bin/cellout: [ -r "${_file}" ] || _die "Could not read ${_file}"
The package is cellout-git, not cellout! (I really need to get my old packages removed from AUR).
Last edited by neurolysis (2012-05-22 22:20:54)
Offline
jasonwryan wrote:This?
┌─[Veles ~] └─╼ grep -R "Could not read" Build/cellout/ Build/cellout/src/cellout: [ -r "${_file}" ] || _die "Could not read ${_file}" Build/cellout/pkg/usr/bin/cellout: [ -r "${_file}" ] || _die "Could not read ${_file}"
The package is cellout-git, not cellout! (I really need to get my old packages removed from AUR).
LOL. I wondered why it was orphaned...
# edit:
┌─[Veles ~]
└─╼ cellout -g BAT0
[###-] 99U
┌─[Veles ~]
└─╼ cellout BAT0
[###-] 99U
Offline
Doesn't work on my T420S, where these files are named differently:
ls /sys/class/power_supply/BAT1
power cycle_count energy_full energy_now model_name present status technology uevent voltage_now
alarm device energy_full_design manufacturer power_now serial_number subsystem type voltage_min_design
And IMO, C seems a bit awkward for something like this. Awk feels more appropriate: http://paste.xinu.at/vfwW5/
Last edited by falconindy (2012-05-22 23:13:07)
Offline
Hmm, I guess I will try to make this more robust. I wonder why the names differ?
Offline
Now rewritten in POSIX awk with substantiative contributions from falconindy.
Offline
I also thought C was a bit awkward for this purpose.
However:
[robin@thor ~/Hacking/git/cellout] % ./cellout
usage: cellout [-g] battery
!1! [robin@thor ~/Hacking/git/cellout] % ./cellout -g
[robin@thor ~/Hacking/git/cellout] % ./cellout BAT0
94D
[robin@thor ~/Hacking/git/cellout] % ./cellout BAT0 -g
usage: cellout [-g] battery
!1! [robin@thor ~/Hacking/git/cellout] % ./cellout -g BAT0
[robin@thor ~/Hacking/git/cellout] %
So yes, it does not display anything when using -g option.
I am not familiar with awk but why test the length of ARGV? isn't it possible to use ARGC?
EDIT:
I can confirm we can definitely use ARGC in awk:
diff --git a/cellout b/cellout
index 7c4b8b6..69526ef 100755
--- a/cellout
+++ b/cellout
@@ -20,10 +20,10 @@ function display_graphical(now, full, status) {
}
BEGIN {
- if (length(ARGV) == 2) {
+ if (ARGC == 2) {
graphical = 0
battery = ARGV[1]
- } else if ((length(ARGV) == 3) && (ARGV[1] == "-g")) {
+ } else if ((ARGC == 3) && (ARGV[1] == "-g")) {
graphical = 1
battery = ARGV[2]
} else {
Last edited by Rolinh (2012-05-24 13:59:05)
Offline
I see you have incorporated the fix I tried to describe.
Just in case anyone would prefer a POSIX sh version, here it is (using uevent):
#!/bin/sh
display_graphical()
{
echo -n '['
i=0;
while [ $i -lt $(( $now_percent / 25 )) ]; do
echo -n '#'
i=$(( $i + 1 ))
done
while [ $i -lt 4 ]; do
echo -n '-'
i=$(( $i + 1 ))
done
echo -n '] '
}
graphical=false
for o in "${@}"; do
case "${o}" in -g) graphical=true;; *) battery="${o}" ;; esac
done
[ -z "${battery}" ] && echo "usage: cellout [-g] <battery>" && exit 1
. "/sys/bus/acpi/drivers/battery/PNP0C0A:00/power_supply/${battery}/uevent"
[ -z "${POWER_SUPPLY_ENERGY_NOW}" ] && prefix=CHARGE || prefix=ENERGY
eval now=\${POWER_SUPPLY_${prefix}_NOW}
eval full=\${POWER_SUPPLY_${prefix}_FULL}
now_percent=$(( ${now} * 100 / ${full} ))
status=$(printf '%c' ${POWER_SUPPLY_STATUS})
${graphical} && display_graphical
echo "${now_percent}${status}"
It's a shameless "feature copy" of cellout, so I used the name, hope you don't mind
This does only depend on a POSIX like shell, and is a little bit shorter
EDIT: fixed a little typo...
Last edited by dammannj (2012-05-25 07:59:34)
Offline
It does not display anything when using -g option.
As shown in the manual, the option must come before the battery ID.
I am not familiar with awk but why test the length of ARGV? isn't it possible to use ARGC?
True, I just copied it verbatim from falconindy's snippet. Done now.
Offline
As shown in the manual, the option must come before the battery ID.
As you can see in what I posted: I tried both without success
Offline
I finally worked out what it is.
Your version of awk is interpreting -g as an option. Try:
cellout -- -g BAT0
Offline
Yep, that did it:
[robin@thor ~/Hacking/git/cellout] % ./cellout -g BAT0
[robin@thor ~/Hacking/git/cellout] % ./cellout -- -g BAT0
[####] 99U
Weird though.
Offline