mirror of
https://github.com/dustinkirkland/byobu
synced 2025-08-24 07:06:19 -07:00
Added battery_state to monitor battery state.
This commit is contained in:
parent
0b0f48733b
commit
1f318a0e23
1 changed files with 85 additions and 0 deletions
85
bin/battery_state
Executable file
85
bin/battery_state
Executable file
|
@ -0,0 +1,85 @@
|
||||||
|
#!/bin/sh -e
|
||||||
|
#
|
||||||
|
# battery_state: print the state of the battery
|
||||||
|
# Copyright (C) 2009 Raphaël Pinson.
|
||||||
|
#
|
||||||
|
# Authors: Raphaël Pinson <raphink@ubuntu.com>
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
|
search () {
|
||||||
|
local str expr
|
||||||
|
str="$1"
|
||||||
|
expr="$2"
|
||||||
|
|
||||||
|
echo "$str" | sed -n "s/${expr}/\1/p"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BATS=$(ls /proc/acpi/battery)
|
||||||
|
NB=$(echo "$BATS" | wc -l)
|
||||||
|
|
||||||
|
for bat in $BATS; do
|
||||||
|
if [ "$NB" -gt 1 ]; then
|
||||||
|
echo -n "$bat: "
|
||||||
|
fi
|
||||||
|
|
||||||
|
# read files once
|
||||||
|
infofile=$(cat "/proc/acpi/battery/$bat/info")
|
||||||
|
statefile=$(cat "/proc/acpi/battery/$bat/state")
|
||||||
|
|
||||||
|
present=$(search "$infofile" "present: *\(.*\)")
|
||||||
|
|
||||||
|
if [ "x${present}" = "xno" ]; then
|
||||||
|
echo "n/a"
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
|
||||||
|
full=$(search "$infofile" "last full capacity: *\(.*\) m[AW]h")
|
||||||
|
warn=$(search "$infofile" "design capacity warning: \(.*\) m[AW]h")
|
||||||
|
low=$(search "$infofile" "design capacity low: \(.*\) m[AW]h")
|
||||||
|
|
||||||
|
rem=$(search "$statefile" "remaining capacity: *\(.*\) m[AW]h")
|
||||||
|
if [ "$rem" -lt "$low" ]; then
|
||||||
|
alert="! "
|
||||||
|
elif [ "$rem" -lt "$warn" ]; then
|
||||||
|
alert="/!\ "
|
||||||
|
else
|
||||||
|
alert=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
percent=$(echo "100*$rem/$full" | bc)
|
||||||
|
state=$(search "$statefile" "charging state: *\(.*\)")
|
||||||
|
|
||||||
|
case $state in
|
||||||
|
charging)
|
||||||
|
sign="+"
|
||||||
|
;;
|
||||||
|
discharging)
|
||||||
|
sign="-"
|
||||||
|
;;
|
||||||
|
charged)
|
||||||
|
sign="="
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
sign=" $state"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
echo "${alert}${percent}%${sign}"
|
||||||
|
done
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue