0

I currently have this as my hardstatus last line on gnu-screen

screenshot

the ~/.screenrc entry is as follows (just incase someone want something similar)

hardstatus alwayslastline '%{= g}[ %{G}%H %{g}][%= %{= w}%?%-Lw%?%{r}(%{W}%n*%f%t%?(%u)%?%{r})%{w}%?%+Lw%?%?%= %{g}][%{B} %d/%m %{W}%c %{g}]'

I wish to include my notebook's battery percentage at the end. I though of using upower for that (new ideas are appreciated), by adding $(upower -d | grep percentage | sed 'some magic stuff') at the end, the problem is that I cannot figure out how to trim out the percentage number using sed. The output of upower -d | grep percentage is:

[roberto@Kasama ~]$upower -d | grep percentage percentage: 81% percentage: 81%

I tried using sed -e 's/percentage\t// but that does not seem to work.

EDIT:

using backtick I managed to print the percentage number by using

$(upower -d | grep percentage | sed -n "1p" | sed -e 's/percentage:..........//') but I do still get some spaces, that cannot be removed by adding more dots, before the actual number%. Any clue on how to clean those?

EDIT2:

got it almost the way I wanted it, I am now using $(upower -d | grep percentage | sed -n "1p" | sed -e 's/^.* //') which returns me 81% the way I wanted it. Now I'm trying to make conditions using %? and %: to print the number in a certain color depending on how low the battery is.

  • I'd suggest AWK instead of sed. Something along the lines of: upower -d|awk '$1 == "percentage:" { power=substr($2, 0, index($2, "%") - 1); if (power < 30) { color="RED"; } else if (power < 80) { color="ORANGE"; } else { color="GREEN";} printf "%d: %s\n", power, color; }'. – Sami Laine Oct 3 '14 at 8:38
  • pretty cool solution, but I wonder how to use those colors in screen hardstatus – Kasama Oct 3 '14 at 15:29
  • The colours part was left as an exercise for the reader. – Sami Laine Oct 3 '14 at 16:19
0

you could try the acpi program with no argument is output the battery name, it's status (Charging/Discharging/Full) the percentage and the estimated remaning lifetime or charging time

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.