Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.windows.x > #641

Re: a battery monitor

From Anton Antimo <anton@safunu.org>
Newsgroups comp.windows.x
Subject Re: a battery monitor
Date 2026-09-11 16:58 -0300
Organization A noiseless patient Spider
Message-ID <874ifvd0gm.fsf@safunu.org> (permalink)
References <87v78oop87.fsf@safunu.org> <877bl48g2v.fsf@debian> <874ig7oezo.fsf@safunu.org>

Show all headers | View raw


Anton Antimo <anton@safunu.org> writes:

> Kragen Javier Sitaker <kragen@canonical.org> writes:
>
>> Anton Antimo <anton@safunu.org> writes:
>>> So, yes, the program is more like a progress bar to be used by some kind
>>> of shell program.  Here's how I've been using it.  My system has this
>>> program called acpi, which gives me battery information:
>>>
>>> %acpi -b
>>> Battery 0: Charging, 91%, 00:18:43 until charged
>>>
>>> I run CWM, the calm window manager.  So from my ~/xinitrc, I run:
>>>
>>> while true; \
>>>   do acpi -b | awk '{printf("%d\n",$4)}' | tr -d '%,' && sleep 60; \
>>>   done | xbattery 220x40-0-0 &
>>
>> This is a good idea!
>
> But take notice of a bug in this script above.  With the &&-conditional
> above the script ends up consuming a lot of CPU if something goes wrong
> in the previous pipeline.  We want to sleep regardless of what happens
> before---or at least exit 1 if the pipeline fails.
>
> Another bug is that the pipeline fails when you plug power in.  The
> percentage is not always at field number 4, so the AWK script is
> naive.

Here's a wiser AWK joint work with tr (with the other bugs crushed).

--8<-------------------------------------------------------->8---
while true; \
  do acpi -b | awk '{for (i=1; i <=NF; ++i) if ($i ~ "%") print $i} \
             | tr -cd '[0-9]' ; sleep 60; done \
  | xbattery 220x40-2-0 &
--8<-------------------------------------------------------->8---

Back to comp.windows.x | Previous — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

a battery monitor Anton Antimo <anton@safunu.org> - 2026-09-01 14:28 -0300
  Re: a battery monitor Kragen Javier Sitaker <kragen@canonical.org> - 2026-09-02 00:52 -0300
    Re: a battery monitor Anton Antimo <anton@safunu.org> - 2026-09-02 12:22 -0300
      Re: a battery monitor Anton Antimo <anton@safunu.org> - 2026-09-11 16:58 -0300
  Re: a battery monitor Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-02 21:45 +0000
    Re: a battery monitor Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-09-03 12:34 +0800
      Re: a battery monitor Eli the Bearded <*@eli.users.panix.com> - 2026-09-03 05:30 +0000
        Re: a battery monitor Lawrence D’Oliveiro <ldo@nz.invalid> - 2026-09-03 21:24 +0000
          Re: a battery monitor Eli the Bearded <*@eli.users.panix.com> - 2026-09-04 02:51 +0000
    Re: a battery monitor David Brown <david.brown@hesbynett.no> - 2026-09-03 09:28 +0200
      Re: a battery monitor boltar@caprica.universe - 2026-09-03 15:55 +0000
        Re: a battery monitor David Brown <david.brown@hesbynett.no> - 2026-09-04 09:07 +0200
          Re: a battery monitor Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-09-04 15:14 +0800
          Re: a battery monitor Lane W <cactus_DAC@yahoo.com> - 2026-09-04 05:32 -0600
          Re: a battery monitor scott@slp53.sl.home (Scott Lurndal) - 2026-09-04 14:29 +0000
          Re: a battery monitor Johann 'Myrkraverk' Oskarsson <johann@myrkraverk.invalid> - 2026-09-04 23:17 +0800
            Re: a battery monitor boltar@caprica.universe - 2026-09-05 09:39 +0000
        Re: a battery monitor gazelle@shell.xmission.com (Kenny McCormack) - 2026-09-04 12:05 +0000
  Re: a battery monitor Anton Antimo <anton@safunu.org> - 2026-09-02 18:48 -0300

csiph-web