* bin/battery: ensure that only one present battery is displayed in the

status area


Signed-off-by: Dustin Kirkland <kirkland@canonical.com>
This commit is contained in:
Dustin Kirkland 2009-06-17 17:45:38 -05:00
commit 82267654f8

View file

@ -23,38 +23,26 @@ search () {
local str expr local str expr
str="$1" str="$1"
expr="$2" expr="$2"
echo "$str" | sed -n "s/${expr}/\1/p" echo "$str" | sed -n "s/${expr}/\1/p"
} }
BATS=$(ls /proc/acpi/battery)
NB=$(echo "$BATS" | wc -l)
if [ "$1" = "--detail" ]; then if [ "$1" = "--detail" ]; then
for bat in $BATS; do for bat in $(ls /proc/acpi/battery); do
cat "/proc/acpi/battery/$bat/info" cat "/proc/acpi/battery/$bat/info"
cat "/proc/acpi/battery/$bat/state" cat "/proc/acpi/battery/$bat/state"
done done
exit 0 exit 0
fi fi
for bat in $BATS; do for bat in $(ls /proc/acpi/battery); do
if [ "$NB" -gt 1 ]; then # make sure that this battery is present
echo -n "$bat: "
fi
# read files once
infofile=$(cat "/proc/acpi/battery/$bat/info") infofile=$(cat "/proc/acpi/battery/$bat/info")
statefile=$(cat "/proc/acpi/battery/$bat/state")
present=$(search "$infofile" "present: *\(.*\)") present=$(search "$infofile" "present: *\(.*\)")
[ "${present}" = "no" ] && continue
if [ "x${present}" = "xno" ]; then # obtain full and remaining battery values
echo "n/a" statefile=$(cat "/proc/acpi/battery/$bat/state")
break
fi
full=$(search "$infofile" "last full capacity: *\(.*\) m[AW]h") full=$(search "$infofile" "last full capacity: *\(.*\) m[AW]h")
rem=$(search "$statefile" "remaining capacity: *\(.*\) m[AW]h") rem=$(search "$statefile" "remaining capacity: *\(.*\) m[AW]h")
@ -85,6 +73,6 @@ for bat in $BATS; do
sign="$state" sign="$state"
;; ;;
esac esac
printf "\005%s%s|%s|\005{-} " "$per_color" "$percent" "$sign" printf "\005%s%s|%s|\005{-} " "$per_color" "$percent" "$sign"
break
done done